mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-06 06:41:56 +00:00
24 lines
501 B
TypeScript
24 lines
501 B
TypeScript
export class Future<T> {
|
|
private _resolve!: (value: T) => void;
|
|
private _reject!: (reason?: any) => void;
|
|
private _promise: Promise<T>;
|
|
|
|
constructor() {
|
|
this._promise = new Promise((resolve, reject) => {
|
|
this._resolve = resolve;
|
|
this._reject = reject;
|
|
});
|
|
}
|
|
|
|
resolve(value: T) {
|
|
this._resolve(value);
|
|
}
|
|
|
|
reject(reason?: any) {
|
|
this._reject(reason);
|
|
}
|
|
|
|
get promise() {
|
|
return this._promise;
|
|
}
|
|
} |