3 ms·
same example with async control flow library and node style callback conventions function getUserInfo(callback) { async.parallel([api.getUser, api.getFriends
by hitgeek 9y ago
same example with async control flow library and node style callback conventions
function getUserInfo(callback) {
async.parallel([api.getUser, api.getFriends, api.getPhoto], callback)
}
- askmike 9y agoEven with a library like async there will be so much boilerplate, since you need to handle (or pass) errors every step of the way. With async/await you only need to deal with errors at the level you actually care about them (using the language build in try/catch block).
- yesbabyyes 9y agoIn the example above, any error will be passed to the callback sent to getUserInfo - i.e., where you care about it.
- samblr 9y agoAgreed there there is boiler plate - but with use of live templates in webstorm (or snippet in VS) - I find it getting easier.
- tracker1 9y agofunction getUserInfo(cb) { Promise.all([ api.getUser(), api.getFriends(), api.getPhoto(), ]).then( ([user, friends, photo]) => cb(null, {user, friends, photo}), cb, ); }
- hitgeek 9y agoI do this with so many libraries now. especially in the react-native ecosystem. I just prefer node style callbacks, so I wrap libraries with promise based APIs with callback based wrappers. hopefully i'm not the only one.