0.1.4 • Published 5 years ago

@shopify/deferred v0.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

@shopify/deferred

A new promise along with methods to change its state.

Installation

$ yarn add @shopify/deferred

Usage

import {Deferred} from '@shopify/deferred';

const deferred = new Deferred();
await deferred.promise;

Resolving with a value:

import {Deferred} from '@shopify/deferred';

const deferred = new Deferred();
deferred.resolve(5);

const five = await deferred.promise;

Promise vs. deferred

A deferred has a promise which functions as a proxy for the future result. While a promise is a value returned by an asynchronous function, a deferred can be resolved or rejected by it's caller which separates the promise from the resolver.