@suchipi/defer
v1.0.0
Published
Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.
Downloads
16
Maintainers
Readme
@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