resolveImmediate.js 558 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. var Promise = require("./Promise");
  3. /**
  4. * Copyright (c) 2013-present, Facebook, Inc.
  5. *
  6. * This source code is licensed under the MIT license found in the
  7. * LICENSE file in the root directory of this source tree.
  8. *
  9. *
  10. */
  11. var resolvedPromise = Promise.resolve();
  12. /**
  13. * An alternative to setImmediate based on Promise.
  14. */
  15. function resolveImmediate(callback) {
  16. resolvedPromise.then(callback)["catch"](throwNext);
  17. }
  18. function throwNext(error) {
  19. setTimeout(function () {
  20. throw error;
  21. }, 0);
  22. }
  23. module.exports = resolveImmediate;