@shopify/deferred

A new promise along with methods to change its state.

Usage no npm install needed!

<script type="module">
  import shopifyDeferred from 'https://cdn.skypack.dev/@shopify/deferred';
</script>

README

@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.