dom-observe
Version:
  • 1.04 kB
text/typescript
export class DeferredPromise<TResolve, TReject>{
public readonly promise: Promise<TResolve>;
public readonly resolve: {
(arg?: TResolve): any;
}
public readonly reject: {
(arg?: TReject): any;
}
public data?: any;
private _is_resolved: boolean = false;
public get isResolved(): boolean{ return this._is_resolved; }
private _is_rejected: boolean = false;
public get isRejected(): boolean{ return this._is_rejected; }
public get isFinished(): boolean{ return this._is_resolved || this._is_rejected; }
/**
* @constructor
*/
constructor(){
let res: any, rej: any;
this.promise = new Promise<TResolve>((resolve, reject) => {
res = resolve;
rej = reject;
});
this.resolve = (...args) => {
this._is_resolved = true;
return res(...args);
};
this.reject = (...args) => {
this._is_rejected = true;
return rej(...args);
};
}
}