Natural Performance Manager
Publish your own packages to the world's most popular software ecosystem with npm Pro.Get started »

defer-promise

2.0.1 • Public • Published

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.

Install

npm i defer-promise

DownloadsWeekly Downloads

15,778

Version

2.0.1

License

MIT

Unpacked Size

4.4 kB

Total Files

5

Last publish

Collaborators

  • avatar