DEV Community

Discussion on: How to rewrite a callback function in Promise form and async/await form in JavaScript

marneborn profile image
Mikael Arneborn

Use bluebirds .from callback function to easily to await on a function that takes a callback).

This only works if your callbacks are called in the standard way though, ie (err, result).

const Promise = require('bluebird');

await Promise.fromCallback(callback => functionThatTakesACallback(arg1, arg2, callback));