5 ms·
There are ways to compose functions, like the deferrable pattern. They just all kind of suck and are poor replacements for having a stack. I'm all for using co
by bascule 15y ago
There are ways to compose functions, like the deferrable pattern. They just all kind of suck and are poor replacements for having a stack.
I'm all for using coroutines to solve this problem. That's the approach taken by my Celluloid::IO library:
https://github.com/tarcieri/celluloid-io https://github.com/tarcieri/celluloid-io
Unfortunately Ryan Dahl is adamantly opposed to coroutines so that's not going to happen in Node any time soon.
- peterhunt 15y agoDeferreds make your code nicer, but they still don't magically make your code composable. What would make Node more attractive is if it supported copy-on-write multithreading and gave me a way to cheat and use asynchronous I/O (like a wait(myFunctionThatTakesACallbackOrDeferred) function)
- bascule 15y agoThere are many ways to compose deferrables, primarily by grouping several of them together into something which is also a deferrable. See the em-scenario gem for examples: https://github.com/athoune/em-scenario https://github.com/athoune/em-scenario Note: I still think this approach sucks. V8 provides a really awesome shared-nothing multithreading scheme via web workers. It's just nobody uses them.
- peterhunt 15y agoOh right that's definitely true and is much more elegant. I was talking about when a function written in synchronous style (in a long stack of synchronous calls) needs to call something asynchronous.
- ufo 15y agoI wouldn't say the problem with Deferreds is composability - the big problem, as you already mentioned, is fragility towards future changes
- guan 15y agoI like Kris Zyp's promises and use them a lot: https://github.com/kriszyp/promised-io https://github.com/kriszyp/promised-io
- no_more_death 15y agoNode supports no language extensions that V8 doesn't. Ryan Dahl says: "Node does not modify the JavaScript runtime. This is for the ECMA committee and V8 to decide. If they add coroutines (which they won't) then we will include it. If they add generators we will include them." See Tim's thread, My Humble Coroutine Proposal (https://groups.google.com/forum/#!topic/nodejs/HJOyNMKLgB8 https://groups.google.com/forum/#!topic/nodejs/HJOyNMKLgB8). Warning: long. So, you don't like javascript? Don't use it. But you won't beat the control over program state offered by javascript -- not until computers understand their programmers well enough to reason about program state. We need better computers, better computer science, and better programmers -- that's all. Then we can replace NodeJS with something better. Until then, NodeJS is almost certainly the most tasteful solution to the most common problems. I hope its replacement meets so high a standard.