Hacker News new | past | comments | ask | show | jobs | submit login

It's been done. One of the best libraries for managing asynchronous code in JS without hiding it away is http://github.com/caolan/async

I agree wholeheartedly, by the way. There's way too much scope for leaky abstractions when you try to hide away the true nature of asynchronous code.

Same reason, I think, why most people are lukewarm about using continuations in web development, like e.g. Seaside does: in principle, very neat, very clean, but it hides away a fundamental aspect of how the web works, which can lead to all sorts of unforeseen behavior re. caching, debugging et cetera.




"There's way too much scope for leaky abstractions when you try to hide away the true nature of asynchronous code."

Done properly, that's not terribly true. Done properly, correct code transformers can actually bring you a lot of power, such as handling exceptions correctly across asynchronous boundaries or enabling much more powerful control flows, such as being able to freely pass in callbacks that themselves may have asynchronous functionality, layered arbitrarily deeply. The only thing that can "leak" is exactly where the asynchronous breaks occur, but it's not that hard to see that.

It's quite debatable that "the true nature" of asynchronous code is in the manually-scheduled hacked up code that you write by hand in Node.js or similar tools. Other environments that don't require that make a good case for saying that the "true nature" of asynchronous code looks like the synchronous code, only with capable scheduling, and the real "leaky abstraction" is the way your terrible, terrible language runtime scheduler is poking out and requiring you to manually transform your relatively simple code into a spaghetti mess to satisfy it. There's your leaky abstraction, and what leaks out is daggers slicing your code to ribbons.


Yeah, I assumed there had to be libraries to do this already, but didn't come across anything that did what I wanted. I'll check out async though, thanks for the heads up.


There are many many attempts at solving this problem, both libraries and preprocessors. None seem to satisfy a large audience, most people seem to deal with the callback nesting and hope to avoid cases where it gets super ugly.

I have a lot bookmarked on github, these are mostly libraries.

https://github.com/coolaj86/futures https://github.com/substack/node-seq https://github.com/marcuswestin/fun https://github.com/creationix/step https://github.com/chriso/chain.js https://github.com/substack/node-chainsaw https://github.com/caolan/async https://github.com/kriszyp/promised-io https://github.com/kriszyp/node-promise https://github.com/technoweenie/node-chain-gang https://github.com/creationix/do https://github.com/willconant/flow-js https://github.com/creationix/conductor

Some branches of CoffeeScript are also trying to ease the pain. Defer keyword didn't make it into CoffeeScript main. My impression is CoffeeScript makes callback hell less ugly anyway, so there is less need for adding a complex language feature that generates unreadable JavaScript.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: