Re:Fixing the callback spaghetti in node.js
by snprbob86 on Thursday September 29, 2011 @04:02AM
(#3051572)
The wiki page says:
So I don't see why not...
[ Parent
| on HN ]
Re:Fixing the callback spaghetti in node.js
by tlrobinson on Thursday September 29, 2011 @04:14AM
(#3051598)
Exactly. The error object is a return value of the "await"-ed function, not an exception that's thrown.
Here's a concrete example. Normally in Node you do something like this:
fs.readFile('/etc/passwd', function (err, data) {
if (err) {
// handle error
}
// normal processing
});
The await version would look like this: await err, data = fs.readFile('/etc/passwd');
if (err) {
// handle error
}
// normal processing
Ideally it would look like this: try {
await data = fs.readFile('/etc/passwd');
// normal processing
} catch (error) {
// handle error
}