|
|
|
|
|
by tlrobinson
5381 days ago
|
|
I really like this idea, but it doesn't seem to do error handling correctly. This is not going to catch most errors occurring in an asynchronous APIs: try {
asyncOperation(function(err, result) {
// ...
});
} catch (e) {
// ...
}
Most errors will occur asynchronously, thus the convention of "err" being the first argument to asynchronous API callbacks in Node.Unless this supports that convention, your code should actually look like: async function magic() {
try {
// code here
await err, bar = doSomething();
if (err) {
throw err;
}
// more code here
await err, boo = doAnotherThing();
if (err) {
throw err;
}
// do even more stuff here
}
catch (e) {
// handle the error
}
}
...or something similar. It's better than the alternative, but not great.This certainly could support the "err" first convention, but APIs that don't use that convention wouldn't work correctly. |
|