deferred.ts 371 B

12345678910111213141516
  1. export class Deferred<T = any> {
  2. resolve?: (reason: T | PromiseLike<T>) => void;
  3. reject?: (reason?: any) => void;
  4. promise: Promise<T>;
  5. constructor() {
  6. this.resolve = undefined;
  7. this.reject = undefined;
  8. this.promise = new Promise((resolve, reject) => {
  9. this.resolve = resolve;
  10. this.reject = reject;
  11. });
  12. Object.freeze(this);
  13. }
  14. }