npm.io
3.0.1 • Published 6 months ago

defer-promise

Licence
MIT
Version
3.0.1
Deps
0
Size
5 kB
Vulns
0
Weekly
0
Stars
1
DeprecatedThis package is deprecated

view on npm npm module downloads Gihub repo dependents Gihub package dependents Node.js CI js-standard-style

Deprecated. Deferred promises have been standardised by the native Promise.withResolvers() method. This library will continue to function correctly but will no longer be maintained.

defer-promise

Isomorphic function returning a deferred promise with resolve and reject methods. If the global Promise.defer() method exists it will use that, else polyfill.

import defer from 'defer-promise'
const deferred = defer()

/* Async function using a callback instead of returning a promise */
doSomething((result, err) => {
  if (err) {
    deferred.reject(err)
  } else {
    deferred.resolve(result)
  }
})

const result = await deferred.promise;

Load anywhere

This library can be loaded anywhere, natively without transpilation.

Common JS:

const defer = require('defer-promise')

Node.js with ECMAScript Module support enabled:

import defer from 'defer-promise'

Modern browser ECMAScript Module:

import defer from './node_modules/defer-promise/index.js'

2015-26 Lloyd Brookes <opensource@75lb.com>. Documented by jsdoc-to-markdown.

Keywords