by jules · 16y ago · 0 comments
http://nodejs.org/jsconf2010.pdf
> Coroutines complicate the mental model while adding only cheap syntactic pleasures.
The problem is just that coroutines are not natural in JS, and people will shoot themselves in the foot all the time.
Some "features" are better left out to allow a bigger audience to write reliable Software. Your milage may vary.
But then again, Erlang is probably a language more "suitable" to high concurrency programming, but node's goal is to make writing scalable networks programs possible for everyone. One might call it the PHP of concurrency : )
I suppose someone who wants them in node.js can just reimplement them as an extension.
Basically callbacks and coroutines don't play well together.
But there were a bunch of reasons for the removal, performance and quality of the initial implementation also played into it AFAIK.
Can you elaborate on this? I thought the opposite: coroutines play very well with callbacks. Callback libraries force you to write programs in continuation passing style. Coroutines let you write asynchronous programs in normal style. Lets assume we have an asynchronous readAsync(callback) function that reads a number and calls the callback with the input when it's ready. Now you're writing your program like this:
readAsync(function(x){
readAsync(function(y){
write(x+y)
})
})
What you want to write is this: x = read() // may block this coroutine, but *not* the entire program
y = read()
write(x+y)
This can be achieved with something like: function read(){
coro = getCurrentCoroutine()
var result
callback = function(x){ result = x; coro.resume() }
readAsync(callback)
yield // stops the current coroutine until it is resumed
return result
}
It seems to me that this is a general way to adapt any callback style library to coroutines.