promise_provider.js 660 Bytes
Newer Older
Patiphan Marak's avatar
Patiphan Marak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
/*!
 * ignore
 */

const assert = require('assert');
const mquery = require('mquery');

/**
 * Helper for multiplexing promise implementations
 *
 * @api private
 */

var store = {
  _promise: null
};

/**
 * Get the current promise constructor
 *
 * @api private
 */

store.get = function() {
  return store._promise;
};

/**
 * Set the current promise constructor
 *
 * @api private
 */

store.set = function(lib) {
  assert.ok(typeof lib === 'function',
    `mongoose.Promise must be a function, got ${lib}`);
  store._promise = lib;
  mquery.Promise = lib;
};

/*!
 * Use native promises by default
 */

store.set(global.Promise);

module.exports = store;