babylon.deferred.ts 1.0 KB

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