promise-back
Augment a thunk such that it returns a promise if applied without a callback.
npm install promise-back --save
You can also use Duo, Bower or download the files manually.
npm stats
API Example
require
var promiseBack =
expose dual interface async function
var read = readFilevar path = var filepath = pathvar encoding = 'utf8'var readable =
NOTE: if you already have a function that takes a callback as it's only parameter, you can just pass it to
promiseBack
. Modules that expose such an interface can be passed directly topromiseBack
without a wrapper; You may also useFunction.prototype.bind
to achieve the same.
use callback interface
//=> Augment a thunk such that it returns a promise if applied without a callback.
use promise interface
//=> Augment a thunk such that it returns a promise if applied without a callback.
API
promiseBack(fn)
arguments
fn: (Function)
Thunk.
returns
(Function)
Returns a function that when applied with a callback, returnsundefined
, otherwise, returns aPromise
.
Contributing
SEE: contributing.md