0.4.1 • Published 9 years ago

promise-back v0.4.1

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

promise-back

Augment a thunk such that it returns a promise if applied without a callback.

Build Status Code Climate js-standard-style

npm install promise-back --save

You can also use Duo, Bower or download the files manually.

npm stats

npm NPM downloads Dependency Status

API Example

require
var promiseBack = require('promise-back')
expose dual interface async function
var read = require('fs').readFile
var path = require('path')
var filepath = path.resolve(__dirname, 'package.json')
var encoding = 'utf8'
var readable = promiseBack(read.bind(null, filepath, encoding))

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 to promiseBack without a wrapper; You may also use Function.prototype.bind to achieve the same.

use callback interface
readable(function (_, str) {
  console.log(JSON.parse(pkg).description)
})
//=> Augment a thunk such that it returns a promise if applied without a callback.
use promise interface
readable()
.then(JSON.parse)
.then(selectn('description'))
.then(console.log)
.catch(console.error)
//=> 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, returns undefined, otherwise, returns a Promise.

Contributing

SEE: contributing.md

Licenses

GitHub license

0.4.1

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago