@beyond-js/pending-promise
v0.0.3
Published
A `PendingPromise` class that extends the native `Promise` to provide externally accessible `resolve` and `reject` methods.
Downloads
170
Readme
@beyond-js/pending-promise
A PendingPromise
class that extends the native Promise
to provide externally accessible resolve
and reject
methods.
Installation
npm install @beyond-js/pending-promise
Usage
import { PendingPromise } from '@beyond-js/pending-promise/main';
const promise = new PendingPromise<string>();
// Resolve the promise later
setTimeout(() => {
promise.resolve('Hello, world!');
}, 1000);
promise.then(value => {
console.log(value); // Output after 1 second: Hello, world!
});
API
PendingPromise
Extends the native Promise
class with externally accessible resolve
and reject
methods.
Constructor
new PendingPromise<T>(executor?: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void)
- executor: Optional executor function that takes
resolve
andreject
functions.