promise_provider.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.PromiseProvider = void 0;
  4. const error_1 = require("./error");
  5. /** @internal */
  6. const kPromise = Symbol('promise');
  7. const store = {
  8. [kPromise]: undefined
  9. };
  10. /**
  11. * Global promise store allowing user-provided promises
  12. * @public
  13. */
  14. class PromiseProvider {
  15. /** Validates the passed in promise library */
  16. static validate(lib) {
  17. if (typeof lib !== 'function')
  18. throw new error_1.MongoInvalidArgumentError(`Promise must be a function, got ${lib}`);
  19. return !!lib;
  20. }
  21. /** Sets the promise library */
  22. static set(lib) {
  23. if (!PromiseProvider.validate(lib)) {
  24. // validate
  25. return;
  26. }
  27. store[kPromise] = lib;
  28. }
  29. /** Get the stored promise library, or resolves passed in */
  30. static get() {
  31. return store[kPromise];
  32. }
  33. }
  34. exports.PromiseProvider = PromiseProvider;
  35. PromiseProvider.set(global.Promise);
  36. //# sourceMappingURL=promise_provider.js.map