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

accept-promises

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

accept-promises

Accept Promises into your heart and/or functions.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

accept-promises

Let them into your heart and/or functions.

Synopsis

var assert = require('assert');
var acceptPromises = require('./');
var Promise = require('bluebird');

var add = acceptPromises(function (a, b) {
  return a + b;
});

var assertIsPromise = function (it) {
  assert(Promise.is(it));
};

assertPromise(add(1, 2));

add(1, 2).then(function (three) {
  assert.equal(3, three);
});

assertPromise(
 add(1, Promise.resolve(2))).then(function (three) {
  assert.equal(3, three);
 })
);

In addition to decorating individual functions, there is also a helper for walking over an object prototype:

function Calculator () {}

Calculator.prototype = acceptPromises.mutateMethods({
  add: function (a, b) { return a + b },
  sub: function (a, b) { return a - b },
  mul: function (a, b) { return a * b },
  div: function (a, b) { return a / b }
});

Description

This module exports a function decorator that will wait for all Promise arguments to a function to settle. This allows you to avoid writing a lot of .then boilerplate in your code, and write things as though they are sync.

Acknowledgements

This is really just the bindSync decorator from z-core pulled out into it's own module, since it was the only part of z-core that I really wanted.

License

MIT

Keywords

FAQs

Package last updated on 06 May 2014

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