Nodeify the result of a promise returning function.
When an API requires that you pass it a function with the signature (...args, cb)
, wrap is a small helper that allows you to instead pass a promise returning function. wrap will nodeify the result of the promise returning function (fulfilment or rejection) by passing its value to the original callback.
One such API that asks for an asynchronous listener function (...args, cb)
is express. When a HTTP request is made, express will call your listener function, if you have one registered for that route. The example below demonstrates how wrap can help you to use promises in such a situation.