as-callback.js 542 B

12345678910111213141516171819
  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) {
  11. callback(null, value);
  12. }),
  13. microtaskDelay.call(function (reason) {
  14. callback(reason);
  15. })
  16. );
  17. };