Skip to content

Promisify wrapper that yields automatic handling of Promise or node-style callback based on invocation parameters.

License

Notifications You must be signed in to change notification settings

zamnuts/promiqueen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

promiqueen

Travis npm npm GitHub stars

A wrapper that detects if node-style callbacks are used. After the wrapper is applied, if a callback is supplied then it is used, but if a callback is missing (i.e. the last parameter is not a function), then a BlueBird promise is used.

Use with regular objects:

var promiqueen = require('promiqueen');

var context = {
    method: promiqueen(function(arg,callback) {
        callback(err,data);
    })
};

// ...

context.method('crown',function(err,data) {
    if ( err ) console.warn(err);
    console.log('data',data);
});

context.method('crown').then(function(data) {
    console.log('data',data);
}).catch(function(err) {
    console.warn(err);
});

Use with classes:

var promiqueen = require('promiqueen');

var SomeClass = function() {};

SomeClass.prototype.method = promiqueen(function(arg,callback) {
    callback(err,data);
});

// ...

var instance = new SomeClass();

instance.method('crown',function(err,data) {
    if ( err ) console.warn(err);
    console.log('data',data);
});

instance.method('crown').then(function(data) {
    console.log('data',data);
}).catch(function(err) {
    console.warn(err);
});

About

Promisify wrapper that yields automatic handling of Promise or node-style callback based on invocation parameters.

Resources

License

Stars

Watchers

Forks

Packages

No packages published