@nodesuite/defer
Summary
Simple deferred Promise
generator.
Installation
pnpm install @nodesuite/defer
Usage
import { defer } from "@nodesuite/defer"
import { someEventfulEmitter } from "./events"
const { resolve, reject, untilResolved } = defer()
someEventfulEmitter.on("someEvent", resolve)
const secondEmitter = new EventEmitter()
secondEmitter.on("secondEvent", resolve)
class Foo {
#resolve
#reject
public constructor({ resolve, reject }) {
this.#resolve = resolve
this.#reject = reject
}
public someSuccessFunction() {
return this.#resolve()
}
public someFailureFunction() {
return this.#reject()
}
}
const foo = new Foo({ resolve, reject })
someEventfulEmitter.on("error", () => foo.someFailureFunction())
await untilResolved()