Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

promise.withresolvers

es-shims21.8kMIT1.0.3

ES Proposal spec-compliant shim for Promise.withResolvers

javascript, ecmascript, polyfill, shim, es-shim API, Promise, promises, withResolvers, defer, deferred, settled, fulfilled, resolved, rejected, allsettled, resolve, race, promise.withresolvers

readme

promise.withresolvers Version Badge

github actions coverage License Downloads

npm badge

ES proposal spec-compliant shim for Promise.withResolvers. Invoke its "shim" method to shim Promise.withResolvers if it is unavailable or noncompliant. Note: a global Promise must already exist: the es6-shim is recommended.

This package implements the es-shim API interface. It works in an ES3-supported environment that has Promise available globally, and complies with the spec.

Most common usage:

var assert = require('assert');
var withResolvers = require('promise.withresolvers');

var obj = withResolvers(Promise);
assert.equal(obj.promise instanceof Promise, true);
assert.equal(typeof obj.resolve, 'function');
assert.equal(typeof obj.reject, 'function');

withResolvers.shim(); // will be a no-op if not needed

var obj2 = Promise.withResolvers();

assert.equal(obj2.promise instanceof Promise, true);
assert.equal(typeof obj2.resolve, 'function');
assert.equal(typeof obj2.reject, 'function');

Tests

Simply clone the repo, npm install, and run npm test

changelog