defer-promise
Isomorphic function returning a deferred promise. Uses native `Promise.defer` if available, else polyfills.
Last updated 7 years ago by 75lb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install defer-promise 
SYNC missed versions from official npm registry.

view on npm npm module month Build Status Dependency Status 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.

const defer = require('defer-promise')
const deferred = defer()

doSomething((result, err) => {
  if (err) {
    deferred.reject(err)
  } else {
    deferred.resolve(result)
  }
})

return deferred.promise;

Load anywhere

This library can be loaded anywhere, natively without transpilation.

Node.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.mjs'

Old browser (adds window.defer):

<script nomodule src="./node_modules/defer-promise/dist/index.js"></script>

© 2015-18 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.

Current Tags

  • 2.0.1                                ...           latest (7 years ago)

8 Versions

  • 2.0.1                                ...           7 years ago
  • 2.0.0                                ...           7 years ago
  • 1.0.2                                ...           7 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           10 years ago
  • 0.1.2                                ...           10 years ago
  • 0.1.1                                ...           10 years ago
  • 0.1.0                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (2)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |