promise-from-callback
v0.1.4
Published
Plugin for promisifying Node.js style callbacks into Promises
Downloads
1
Readme
promise-from-callback
Plugin for promisifying Node.js style callback
s into Promise
s.
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);