Utility library to wrap async functions with last callback argument to promise returning functions
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.md
package.json
q-wrap.js

README.md

q-wrap

Utility library to wrap async functions with last callback argument to promise returning functions.

Usage

Convert callback-based function

var convert = require('q-wrap').convert,
    fs = require('fs'),

    readFile = convert(fs.readFile);

readFile('test.txt')
    .then(function(content) {
        console.log(content);
    })
    .fail(function(err) {
        console.error('Error opening file: %s', err);
    })

Execute callback-based function

var execute = require('q-wrap').execute,
    fs = require('fs');

execute(fs.readFile, 'test.txt')
    .then(function(content) {
        console.log(content);
    })
    .fail(function(err) {
        console.error('Error opening file: %s', err);
    })