Skip to content

Turn functions that return promises into next-style middleware

Notifications You must be signed in to change notification settings

Brinkbit/nexthenify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nexthenify

Useful for developing asynchronous express middleware

Turn this:

foo( 'someValue' )
.then(function bar() {
    // we finished
});

into this:

// bar expects a callback where the last argument is a `done` or `next` callback
bar( 'someValue', function( someValue, next ) {
    foo( someValue, next );
});

Install

npm i --save nexthenify

Examples

Basic usage

const nexthenify = require( 'nexthenify' );

function foo( value ) {
    return new Promise(( resolve, reject ) => {
        if ( value === 1 ) resolve( 'is 1' );
        else reject( 'not 1' );
    });
}

bar( 'someValue', nexthenify( foo ));

Optionally pass a context to use:

bar( 'someValue', nexthenify( foo, this ));

Tests

Requires gulp: npm i -g gulp

npm test

About

Turn functions that return promises into next-style middleware

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published