The @esfx/async-deferred
package provides the Deferred
class, an async coordination primitive.
npm i @esfx/async-deferred
import { Deferred } from "@esfx/async-deferred";
const deferred = new Deferred();
// to resolve the deferred:
deferred.resolve(value);
// to reject the deferred:
deferred.reject(error);
// get the promise for the deferred:
deferred.promise;
You can read more about the API here.