• Version 4.0.1
  • Published
  • 3.83 kB
  • No dependencies
  • MIT license


npm i p-defer
yarn add p-defer
pnpm add p-defer


Create a deferred promise



function pDefer

pDefer: <ValueType>() => DeferredPromise<ValueType>;
  • Create a deferred promise.

    Example 1

    import pDefer from 'p-defer';
    function delay(milliseconds) {
    const deferred = pDefer();
    setTimeout(deferred.resolve, milliseconds, '🦄');
    return deferred.promise;
    console.log(await delay(100));
    //=> '🦄'


interface DeferredPromise

interface DeferredPromise<ValueType> {}

    property promise

    promise: Promise<ValueType>;
    • The deferred promise.

    method reject

    reject: (this: void, reason?: unknown) => void;
    • Reject the promise with a provided reason or error.

      Parameter reason

      The reason or error to reject the promise with.

    method resolve

    resolve: (this: void, value?: ValueType | PromiseLike<ValueType>) => void;
    • Resolves the promise with a value or the result of another promise.

      Parameter value

      The value to resolve the promise with.

    Package Files (1)

    Dependencies (0)

    No dependencies.

    Dev Dependencies (3)

    Peer Dependencies (0)

    No peer dependencies.


    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/p-defer.

    • Markdown
    • HTML
      <a href="https://www.jsdocs.io/package/p-defer"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>