promise_provider.js 677 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*!
  2. * ignore
  3. */
  4. 'use strict';
  5. const assert = require('assert');
  6. const mquery = require('mquery');
  7. /**
  8. * Helper for multiplexing promise implementations
  9. *
  10. * @api private
  11. */
  12. const store = {
  13. _promise: null
  14. };
  15. /**
  16. * Get the current promise constructor
  17. *
  18. * @api private
  19. */
  20. store.get = function() {
  21. return store._promise;
  22. };
  23. /**
  24. * Set the current promise constructor
  25. *
  26. * @api private
  27. */
  28. store.set = function(lib) {
  29. assert.ok(typeof lib === 'function',
  30. `mongoose.Promise must be a function, got ${lib}`);
  31. store._promise = lib;
  32. mquery.Promise = lib;
  33. };
  34. /*!
  35. * Use native promises by default
  36. */
  37. store.set(global.Promise);
  38. module.exports = store;