As a concrete demonstrate, in ECMAScript 6, which has generators (= shallow coroutines), you'll be to do transforms like this:
function logUserName() {
var user = getUserSync();
console.log(user.name);
}
// oh no, getting a user became async!
var logUserName = Q.async(function *() {
var user = yield getUserAsync();
console.log(user.name);
});
Note that the language is still single-threaded, and `getUserAsync()` doesn't block execution.A vivid example of this is at http://taskjs.org/.
A better logUserName() would let the caller handle that either by taking a callback or returning a promise. But now you've passed the buck to the caller. And now it has to be async too, all the way up the callstack.
This is the worst thing about async code regardless of whether its callbacks or promises: going to sync to async requires you to transform all code all the way up the callstack.
And yes, you always have to keep inserting `yield` all the way up the stack; you can't "hide" the asynchronicity.
I think this is good. It's important to explicitly call out the asynchronous points of execution in your code. But at the same time, the only transformation you end up needing to do is inserting `yield`.
Also, fix the semicolons. Apparently that's a thing.