1.0.1 • Published 7 years ago

backthen v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

backthen

build status codecov Code Climate

Run a callback as a thenable

Usage

var backthen = require('backthen');
var fs = require('fs');

/*
 * @param {function} func - function to call
 * @param {object} scope - scope for func
 * @param {...any} params - parameters for the function
 *
 * @return {Promise} 
 */
backthen(fs.stat, null, 'file.txt')
  .then(statFulfilled)
  .catch(statRejected)

// Receives array if callback
// invoked with multiple params;
// otherwise a single value
function statFulfilled(stat) {
  // handle the fulfillment
}

function statRejected(err) {
  // handle the rejection
}