Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 416 Bytes

README.md

File metadata and controls

25 lines (17 loc) · 416 Bytes

@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