deferred.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Wrapper class for promise with external resolve and reject.
  3. */
  4. export class Deferred<T> {
  5. /**
  6. * The promise associated with this deferred object.
  7. */
  8. public readonly promise: Promise<T>;
  9. private _resolve: (value?: T | PromiseLike<T>) => void;
  10. private _reject: (reason?: any) => void;
  11. /**
  12. * The resolve method of the promise associated with this deferred object.
  13. */
  14. public get resolve() {
  15. return this._resolve;
  16. }
  17. /**
  18. * The reject method of the promise associated with this deferred object.
  19. */
  20. public get reject() {
  21. return this._reject;
  22. }
  23. /**
  24. * Constructor for this deferred object.
  25. */
  26. constructor()
  27. {
  28. this.promise = new Promise((resolve, reject) => {
  29. this._resolve = resolve;
  30. this._reject = reject;
  31. });
  32. }
  33. }