-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Synchronous prefix to solve pyramids-of-doom (while being backwards compatible) #104
Comments
function foo(cb) {
setTimeout(function() {
cb(null, 1, 2, 3);
}, 1000);
}
console.log(&foo()) What is the logged object here? Btw, pyramid of doom is not really an issue with generators and promises (and co(function* () {
var content = yield get('http://google.com');
console.log(content);
}); |
@gladys123 are you talking about adding this in core? |
@gladys123 if you want such a drastic change you'll have to take it up to TC39. I don't think this is the place to discuss such changes. Also - I agree with what @madbence said this is practically a non-issue with promises+generators or async/await in ES7. Even today with just promises today the nesting wouldn't really be an issue. Alternatives such as the 'classic' async library or even just organizing your callbacks better could be equally effective. |
Also, you can play with sweet.js to achieve |
@gladys123 iojs gets its javascript runtime from V8, which in term implements it according to the ECMAScript spec -- the best place to start if you want to propose changes is esdiscuss. |
Pyramids of doom are a common issue with the callback orientated architecture. While they can be countered in many ways, I believe there's a need for a simple, versatile, and backwards compatible feature that fixes it.
&: the call synchronously prefix.
console.log( &request('https://www.google.com').body )
is equivalent toEffect
Execution of the rest of the block is paused until the async function returns, making it effectively synchronous. The callback parameters are returned, as an object.
Example
Before:
After:
Compatibility
This would allow calling any async function synchronously. It can be implemented with some simple pre-processing, without any changes to V8 and it would be 100% backwards compatible with existing code.
Do we really need it?
I think this is the simplest solution. Pyramids of doom are faced by people new to node universally, and this resolves it without the need of any external modules.
With io.js, let's advance the platform and embrace useful change that are backwards compatible.
The text was updated successfully, but these errors were encountered: