Consider promisifying callbacks
EwanValentine opened this issue · comments
Ewan Valentine commented
Line 29 in 6a1c27c
You can convert callbacks into promises, by doing:
function getUser(id) {
return new Promise((resolve, reject)) => {
User.get(id, (user, err) => {
if (err) {
reject(err);
return;
}
resolve(user);
});
});
}
// Example useage
await getUser(id);
It's more idiomatic to avoid callbacks if it can be helped, but some libraries are still callback based. Which is fine, but if you wanted to bring it into an async/await world, something like the above works.