@tempots/std
deferred() function
Creates a deferred object. A deferred object is a promise that can be resolved or rejected.
Signature:
deferred: <T>() => {
promise: Promise<T>;
resolve: (value: T) => void;
reject: (reason?: unknown) => void;
}
Returns: { promise: Promise<T>; resolve: (value: T) => void; reject: (reason?: unknown) => void; }
A deferred object.
Example
const { promise, resolve, reject } = deferred<number>()
promise.then((value) => {
console.log(value)
})
resolve(42)