p-defer

  • Version 4.0.0
  • Published
  • 4.21 kB
  • No dependencies
  • MIT license

Install

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

Overview

Create a deferred promise

Index

Functions

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));
    //=> '🦄'

Interfaces

interface DeferredPromise

interface DeferredPromise<ValueType> {}

    property promise

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

    method reject

    reject: (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: (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.

    Badge

    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
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/p-defer)
    • 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>