https://github.com/75lb/defer-promise
Isomorphic function returning a deferred promise. Uses native `Promise.defer` where available, else polyfills
https://github.com/75lb/defer-promise
deferred javascript promise
Last synced: 8 months ago
JSON representation
Isomorphic function returning a deferred promise. Uses native `Promise.defer` where available, else polyfills
- Host: GitHub
- URL: https://github.com/75lb/defer-promise
- Owner: 75lb
- License: mit
- Created: 2015-10-25T17:28:09.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-03-29T22:38:32.000Z (about 4 years ago)
- Last Synced: 2025-02-02T08:31:51.984Z (over 1 year ago)
- Topics: deferred, javascript, promise
- Language: JavaScript
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.org/package/defer-promise)
[](https://www.npmjs.org/package/defer-promise)
[](https://github.com/75lb/defer-promise/network/dependents?dependent_type=REPOSITORY)
[](https://github.com/75lb/defer-promise/network/dependents?dependent_type=PACKAGE)
[](https://github.com/75lb/defer-promise/actions/workflows/node.js.yml)
[](https://github.com/feross/standard)
# 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.
```js
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:
```js
const defer = require('defer-promise')
```
Node.js with ECMAScript Module support enabled:
```js
import defer from 'defer-promise'
```
Modern browser ECMAScript Module:
```js
import defer from './node_modules/defer-promise/index.js'
```
* * *
© 2015-22 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).