As a curious and perhaps naive aside, I've been wondering why the programmer should need to care about asynchronous execution of code at all. Can't it all be abstracted under a procedural layer and let the OS worry about not blocking anything? The advent of promises, async.js, and other paradigms tell me that people still kind of want to write code that does one thing after another, then another, then another.
Callback Hell (2016)
11–20 of 170 posts
Re: Callback Hell (2016)
#12Not sure this problem goes away by giving names to anonymous functions, which seems to be his suggestion
Re: Callback Hell (2016)
#13Oh, and callbacks definitely exist in other languages, like C.
What's the deal with this trend of setting up a whole website for a (basic) blog post?
Re: Callback Hell (2016)
#14Earlier quoted context omitted.
Could you elaborate? Coming from Lua I always found the nesting of anonymous functions messy and wondered why they weren't done as in the article.
Promises and, more recently, Observables. Simply put: A promise resolves to a single value asynchronously, an observable resolves to (or emits) multiple values asynchronously (over time). Taken from here: http://stackoverflow.com/questions/36064303/what-are-the-dif...
"The purpose of async/await functions are to simplify the behavior of using promises synchronously and to perform some behavior on a group of Promises. Just like Promises are similar to structured callbacks, async/await is similar to combining generators and promises." https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re: Callback Hell (2016)
#15Re: Callback Hell (2016)
#16Lot of blabbling for a simple concept: do not abuse nesting. It's the case with control statements, it's still the case with functions, and even more with async functions. Oh, and callbacks definitely exist in other languages, like C. What's the deal with this trend of setting up a whole website for a (basic) blog post?
Re: Callback Hell (2016)
#17Last updated in 2012. A lot has changed since.
Re: Callback Hell (2016)
#18Last updated in 2012. A lot has changed since.
Could you elaborate? Coming from Lua I always found the nesting of anonymous functions messy and wondered why they weren't done as in the article.
Also there are now many more libraries that use native ES6 promises.
Before:
function getPhoto(callback) {
someCustomHttpGet("/favorite_photo_id", function(err, data) {
if (err) {
return callback(err)
}
try {
var dataJson = JSON.parse(data)
someCustomHttpGet(dataJson.url, function(err, data) {
if (err) {
return callback(err)
}
callback(undefined, processData(data))
})
}catch(e) {
callback(e)
}
})
}
After: async function getPhoto() {
const data = await fetch("/favorite_photo_id")
const dataJson = await data.json()
const photoData = await fetch(dataJson.url)
return processData(photoData)
}
The example may be a bit contrived, but you get the idea.Re: Callback Hell (2016)
#19Earlier quoted context omitted.
Could you elaborate? Coming from Lua I always found the nesting of anonymous functions messy and wondered why they weren't done as in the article.
Promises and async/await. This page is so outdated it shouldn't exist.