Whith the arriving of generators to javascript and the help of Aryn is possible to use coroutines and CSP(Communicating Sequential Processes) in Node.js or in the client-side.
Aryn + Promise example in Node.js:
function getUsername(id) {
return new Promise(function(resolve, reject) {
db.query('select username from user where id = ?', [id], function(r){
resolve(r[0].username)
})
})
}
// your coroutine
aryn.run(function*(){
var username = yield getUsername(id)
console.log(username)
})
Using Aryns drive function:
db = aryn.drive(require('db'))
var getUsername = aryn.def(function*(){
return yield aryn.receive(db.query('select username from user where id = ?', [id]))
})
aryn.run(function*(){
var username = yield getUsername(id)
console.log(username)
})
prompt()function.showModalDialog. I would not recommended doing this, though.