p-defer
Create a deferred promise
Last updated 2 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install p-defer 
SYNC missed versions from official npm registry.

p-defer

Create a deferred promise

Don't use this unless you know what you're doing. Prefer the Promise constructor.

Install

npm install p-defer

Usage

import pDefer from 'p-defer';

function delay(milliseconds) {
	const deferred = pDefer();
	setTimeout(deferred.resolve, milliseconds, '????');
	return deferred.promise;
}

console.log(await delay(100));
//=> '????'

The above is just an example. Use delay if you need to delay a promise.

API

pDefer()

Returns an object with a promise property and functions to resolve() and reject().

Related

  • p-lazy - Create a lazy promise that defers execution until .then() or .catch() is called
  • More…

Current Tags

  • 4.0.1                                ...           latest (2 years ago)

7 Versions

  • 4.0.1                                ...           2 years ago
  • 4.0.0                                ...           5 years ago
  • 3.0.0                                ...           7 years ago
  • 2.1.0                                ...           7 years ago
  • 2.0.1                                ...           7 years ago
  • 2.0.0                                ...           7 years ago
  • 1.0.0                                ...           9 years ago

Copyright 2013 - present © cnpmjs.org | Home |