0.1.4 • Published 6 years ago

promise-from-callback v0.1.4

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

promise-from-callback

npm version

Plugin for promisifying Node.js style callbacks into Promises.

Compatible with all valid Promises/A+ implementations including bluebird, Q, etc..

Example

const fs = require('fs');

// Just requiring the module will extend the existing Promise API
require('promise-from-callback');

Promise
  .fromCallback(callback => fs.readFile('filename.txt', callback))
  .then(buffer => buffer.toString().trim())
  .fromCallback((filename, callback) => fs.readFile(filename, callback))
  // ...

Installation

NPM

npm install promise-from-callback

Browser

<script type="application/javascript" src="promise-from-callback.js"></script>

API Reference

Promise.fromCallback(fn, thisArg)

Promise
  .fromCallback(callback => fs.readFile('test.txt', callback))
  .then(console.log)

Promise#fromCallback(fn, thisArg)

Promise
  .resolve('test.txt')
  .fromCallback((filename, callback) => fs.readFile(filename, callback))
  .then(console.log);
0.1.4

6 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago