Creates a deferred promise, allowing manual resolution or rejection.
import { deferred } from "@mrspartak/promises"import { readStream } from "./stream"// Create a deferred promiseconst { promise, resolve, reject } = deferred<void>()// Read the stream in chunks and then resolve the promiseconst stream = await readStream()let data = ''stream.on('data', (chunk) => { data += chunk})stream.on('end', () => { resolve()})// Resolve the promise with the dataawait promiseconsole.log(data) // Data is ready Copy
import { deferred } from "@mrspartak/promises"import { readStream } from "./stream"// Create a deferred promiseconst { promise, resolve, reject } = deferred<void>()// Read the stream in chunks and then resolve the promiseconst stream = await readStream()let data = ''stream.on('data', (chunk) => { data += chunk})stream.on('end', () => { resolve()})// Resolve the promise with the dataawait promiseconsole.log(data) // Data is ready
The type of the value that the promise resolves to.
An object containing the promise, resolve, and reject functions.
Creates a deferred promise, allowing manual resolution or rejection.
Example