Skip to content
/ defer Public

Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

License

Notifications You must be signed in to change notification settings

suchipi/defer

Repository files navigation

@suchipi/defer

Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

Usage

import Defer from "@suchipi/defer";

function spinToWin(): Promise<string> {
  const defer = new Defer<string>();

  if (Date.now() % 2 === 0) {
    defer.resolve("You did it!");
  } else {
    defer.reject(new Error("Oh no!"));
  }

  return defer.promise;
}

License

MIT

About

Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published