Deferred.js 803 B

12345678910111213141516171819202122232425262728
  1. /*
  2. Copyright 2018 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import '../_version.js';
  8. /**
  9. * The Deferred class composes Promises in a way that allows for them to be
  10. * resolved or rejected from outside the constructor. In most cases promises
  11. * should be used directly, but Deferreds can be necessary when the logic to
  12. * resolve a promise must be separate.
  13. *
  14. * @private
  15. */
  16. class Deferred {
  17. /**
  18. * Creates a promise and exposes its resolve and reject functions as methods.
  19. */
  20. constructor() {
  21. this.promise = new Promise((resolve, reject) => {
  22. this.resolve = resolve;
  23. this.reject = reject;
  24. });
  25. }
  26. }
  27. export { Deferred };