Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 3 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 (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-03-29T22:38:32.000Z (almost 3 years ago)
- Last Synced: 2024-09-24T07:07:19.702Z (3 months 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
[![view on npm](https://badgen.net/npm/v/defer-promise)](https://www.npmjs.org/package/defer-promise)
[![npm module downloads](https://badgen.net/npm/dt/defer-promise)](https://www.npmjs.org/package/defer-promise)
[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/defer-promise)](https://github.com/75lb/defer-promise/network/dependents?dependent_type=REPOSITORY)
[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/defer-promise)](https://github.com/75lb/defer-promise/network/dependents?dependent_type=PACKAGE)
[![Node.js CI](https://github.com/75lb/defer-promise/actions/workflows/node.js.yml/badge.svg)](https://github.com/75lb/defer-promise/actions/workflows/node.js.yml)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](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 \<[email protected]\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).