util.js 880 B

12345678910111213141516171819202122232425
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.createPromiseCallback = function () {
  4. var cb;
  5. if (!Promise) {
  6. cb = function () { };
  7. cb.promise = {};
  8. var throwPromiseNotDefined = function () {
  9. throw new Error('Your Node runtime does support ES6 Promises. ' +
  10. 'Set "global.Promise" to your preferred implementation of promises.');
  11. };
  12. Object.defineProperty(cb.promise, 'then', { get: throwPromiseNotDefined });
  13. Object.defineProperty(cb.promise, 'catch', { get: throwPromiseNotDefined });
  14. return cb;
  15. }
  16. var promise = new Promise(function (resolve, reject) {
  17. cb = function (err, data) {
  18. if (err)
  19. return reject(err);
  20. return resolve(data);
  21. };
  22. });
  23. cb.promise = promise;
  24. return cb;
  25. };