as-callback.js 532 B

123456789101112131415
  1. "use strict";
  2. var ensurePlainFunction = require("../../object/ensure-plain-function")
  3. , ensureThenable = require("../../object/ensure-thenable")
  4. , microtaskDelay = require("../../function/#/microtask-delay");
  5. module.exports = function (callback) {
  6. ensureThenable(this);
  7. ensurePlainFunction(callback);
  8. // Rely on microtaskDelay to escape eventual error swallowing
  9. this.then(
  10. microtaskDelay.call(function (value) { callback(null, value); }),
  11. microtaskDelay.call(function (reason) { callback(reason); })
  12. );
  13. };