← Snippets

Promise for Callback Function

Added December 27, 2020

Resolve a value that gets returned in the callback of a function (async operation) using a Promise.

1return new Promise((resolve, reject) => {
2 functionWithCallback(cbValue => {
3 resolve(cbValue)
4 })
5 .on('error', err => {
6 reject('Error: ' + err.message)
7 })
8}
9