Skip to content

Plugin for promisifying Node.js style callbacks into Promises

License

Notifications You must be signed in to change notification settings

funny-falcon-at-joomcode/promisify

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'))
  .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);

About

Plugin for promisifying Node.js style callbacks into Promises

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%