defer-promise

defer-promise

Deferred promises have been standardised by the native Promise.withResolvers() method. This library will continue to function correctly but will no longer be maintained.
Last updated 10 years ago by 75lb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install defer-promise 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 3.0.1                                ...           latest (9 months ago)

10 Versions

  • 3.0.1 [deprecated]           ...           9 months ago
  • 3.0.0 [deprecated]           ...           5 years ago
  • 2.0.1 [deprecated]           ...           8 years ago
  • 2.0.0 [deprecated]           ...           8 years ago
  • 1.0.2 [deprecated]           ...           8 years ago
  • 1.0.1 [deprecated]           ...           10 years ago
  • 1.0.0 [deprecated]           ...           10 years ago
  • 0.1.2 [deprecated]           ...           11 years ago
  • 0.1.1 [deprecated]           ...           11 years ago
  • 0.1.0 [deprecated]           ...           11 years ago
Maintainers (1)
Downloads
Total 31
Today 0
This Week 0
This Month 13
Last Day 0
Last Week 0
Last Month 11
Dependencies (0)
None
Dev Dependencies (1)
Dependents (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE