Tutorial by Examples

Callback-based: db.notification.email.find({subject: 'promisify callback'}, (error, result) => { if (error) { console.log(error); } // normal code here }); This uses bluebird's promisifyAll method to promisify what is conventionally callback-based code like above. blueb...
Sometimes it might be necessary to manually promisify a callback function. This could be for a case where the callback does not follow the standard error-first format or if additional logic is needed to promisify: Example with fs.exists(path, callback): var fs = require('fs'); var existsAsync =...
function wait(ms) { return new Promise(function (resolve, reject) { setTimeout(resolve, ms) }) }

Page 1 of 1