Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promise-resolver

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-resolver

Turn a promises resolver methods into a node style callback

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

promise-resolver Build Status

Turn a promises resolver methods into a node style callback

Install

$ npm install --save promise-resolver

Usage

var promiseResolver = require('promise-resolver');

new Promise(function (resolve, reject) {
  var cb = promiseResolver(resolve, reject, passThroughCallback);
  
  cb(new Error('...')); // rejects promise and calls passThroughCallback with same args
  cb(null, 'result'); // resolves promise and calls passThroughCallback with same args
});

API

promiseResolver(resolve, reject, passThrough)

All arguments should be functions, null, or undefined.

  • resolve - promise resolve function
  • reject - promise reject function
  • passThrough - a "pass through" node style (error first) callback.

Returns a node style callback: cb(err, result...)

Calling the callback will resolve or reject the promise (depending on the err argument). If it exists, the passThrough callback will be called with the same arguments.

promiseResolver.defer(passThrough, Promise)

  • passThrough - a "pass through" node style callback as described above
  • Promise - an alternate Promise constructor (will use global.Promise by default).

The return value is a standard defer object with an additional cb property that is a node style resolver callback.

var defer = promiseResolver(passThroughCallback);
var cb = defer.cb;
  
cb(new Error('...')); // rejects promise and calls passThroughCallback with same args
cb(null, 'result'); // resolves promise and calls passThroughCallback with same args

return defer.promise;

defer.resolve, and defer.reject are also available on the defer object.

License

MIT © James Talmage

Keywords

FAQs

Package last updated on 14 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc