@suchipi/defer
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@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

Package Sidebar

Install

npm i @suchipi/defer

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

3.71 kB

Total Files

7

Last publish

Collaborators

  • suchipi