promiseCallback.js 532 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. const PROMISE_SYMBOL = Symbol('promiseCallback');
  6. function promiseCallback() {
  7. let resolve, reject;
  8. function callback(err, ...args) {
  9. if (err) return reject(err);
  10. resolve(args.length > 1 ? args : args[0]);
  11. }
  12. callback[PROMISE_SYMBOL] = new Promise((res, rej) => {
  13. resolve = res, reject = rej;
  14. });
  15. return callback;
  16. }
  17. exports.promiseCallback = promiseCallback;
  18. exports.PROMISE_SYMBOL = PROMISE_SYMBOL;