Skip to content

Easily convert objects, functions and METHODs to the Q promise API

Notifications You must be signed in to change notification settings

goraxan/promisemonkey

This branch is 1 commit ahead of eugeneware/promisemonkey:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5b03728 · Oct 30, 2023

History

13 Commits
May 19, 2013
May 19, 2013
May 19, 2013
May 18, 2013
Jun 11, 2013
Oct 30, 2023
Jun 11, 2013

Repository files navigation

promisemonkey

Easily convert objects, functions and METHODs to the Q promise API

Installation

You can install promisemonkey through npm:

$ npm install promisemonkey

Example

Access standard node APIs as promises

You can easily acccess the standard node APIs as promises:

var promisify = require('promisemonkey');
var fs = promisify('fs');
fs.stat(filePath)
  .then(function (stats) {
    expect(stats.size).to.be.above(0);
  });

Convert an object

You can pass through a object with methods and then an array of the method names to promisify:

var promisify = require('promisemonkey');

// Pass through an object and array of method names
var fs = promisify.convert(require('fs'), ['readFile', 'stat']);

// All the underlying functions should be accessible
var contents = fs.readFileSync(filePath).toString();
expect(contents.length).to.be.above(0);

// You can then use the object methods which are now promisified
fs.stat(filePath)
  .then(function (stats) {
    expect(stats.size).to.be.above(0);
    return fs.readFile(filePath);
  })
  .then(function (contents) {
    expect(contents.length).to.be.above(0);
  })

Convert a function

And, of course you can promisify a plain old function

var readFile = promisify.convert(require('fs').readFile);
readFile(filePath)
  .then(function (contents) {
    expect(contents.length).to.be.above(0);
  })

About

Easily convert objects, functions and METHODs to the Q promise API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%