Re:Node v8.0.0 Released
by p5k on Tuesday May 30, 2017 @05:33PM
(#14448721)
Notejs should get promise versions of its current callback-based APIs:
Should be:
[ Parent
| on HN ]
It really should be:
try{
x = await fs.writeFilePromise("Hello, World", "helloworld.txt")
console.log("done!")
}
catch(error)
{
console.error(error) // or console.log
}
This takes advantage of promises fully.This was tried many years ago. At that time, Promises/A+ was not finalized, and the community could not agree on which Promise specification was best, or even if one was needed at all.
Callbacks are lightest-weight re: CPU & memory overhead, so it was decided that core APIs should implement that, and developers can override using promisify (via e.g. Bluebird or the new `util.promisify()`) as they need. But putting that kind of assumption in core could lead to significant pain.