callbackpromise

0.1.2 • Public • Published

callbackpromise

Wrap a callback so that the result is captured as a promise.

Usage

Returns a wrapper function that when executed will execute the original function and capture the result. The captured result is exposed as a Promise. If the callback returns a value then the promise resolves with that value. If the callback throws a value then the promise rejects with that value. Will return the captured result or error.

Example

function callback( error, value ) { if ( error !== undefined ) { throw error; } return value; }

let cbFunc1 = callbackPromise( callback ); cbFunc1( undefined, true ); console.log( cbFunc1.promise );

Promise { true }

let cbFunc2 = callbackPromise( callback ); cbFunc2( false, undefined ); console.log( cbFunc2.promise );

Promise { false }

License

ISC

Readme

Keywords

Package Sidebar

Install

npm i callbackpromise

Weekly Downloads

2

Version

0.1.2

License

ISC

Last publish

Collaborators

  • kavlon