defer-promise

Isomorphic function returning a deferred promise. Uses native `Promise.defer` if available, else polyfills.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
defer-promise
203.0.08 months ago7 years agoMinified + gzip package size for defer-promise in KB

Readme

view on npm npm module downloads Gihub repo dependents Gihub package dependents Node.js CI js-standard-style
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-22 Lloyd Brookes \<75pound@gmail.com\>. Documented by jsdoc-to-markdown.