Node.js API uses callback approach for its async IO architecture, the next feature I'll add to Aryn is about addressing callback approach converting it to the Aryn way.
There is two proposals:
Channelify, convert callbacks to channels.
var fs = aryn.channelify(require('fs'))
var fileCh = fs.readFile('file.txt')
aryn.run(function*(){
var content = yield receive(fileCh)
})
Suspendify, make the callback stops the runner and unblock once the task is done, or throws on error.
var fs = aryn.suspendify(require('fs'))
aryn.run(function*(){
var content = yield receive(fs.readFile('file.txt'))
})
Both channelify and suspendify are supposed not to be used as function names in the final API, these are just for concepts explanation.
I like more the second approach for several reasons:
1 - It is decoupled to channels, but can be easily integrated with it passing content through a channel.
2 - It is integrated with the receive operation which is consistent with receive(promise) feature already implemented in Aryn.
3 - Allows natural error handling with try/catch, example:
Node.js API uses callback approach for its async IO architecture, the next feature I'll add to Aryn is about addressing callback approach converting it to the Aryn way.
There is two proposals:
Both
channelify
andsuspendify
are supposed not to be used as function names in the final API, these are just for concepts explanation.I like more the second approach for several reasons: 1 - It is decoupled to channels, but can be easily integrated with it passing
content
through a channel. 2 - It is integrated with thereceive
operation which is consistent withreceive(promise)
feature already implemented in Aryn. 3 - Allows natural error handling withtry/catch
, example:So, what do you think?