$ cnpm install defer-promise
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.
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;
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.
Copyright 2013 - present © cnpmjs.org | Home |