asyncGeneratorDelegate.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. "use strict";
  2. exports.__esModule = true;
  3. var _iterator = require("../core-js/symbol/iterator");
  4. var _iterator2 = _interopRequireDefault(_iterator);
  5. var _symbol = require("../core-js/symbol");
  6. var _symbol2 = _interopRequireDefault(_symbol);
  7. var _promise = require("../core-js/promise");
  8. var _promise2 = _interopRequireDefault(_promise);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. exports.default = function (inner, awaitWrap) {
  11. var iter = {},
  12. waiting = false;
  13. function pump(key, value) {
  14. waiting = true;
  15. value = new _promise2.default(function (resolve) {
  16. resolve(inner[key](value));
  17. });
  18. return {
  19. done: false,
  20. value: awaitWrap(value)
  21. };
  22. }
  23. ;
  24. if (typeof _symbol2.default === "function" && _iterator2.default) {
  25. iter[_iterator2.default] = function () {
  26. return this;
  27. };
  28. }
  29. iter.next = function (value) {
  30. if (waiting) {
  31. waiting = false;
  32. return value;
  33. }
  34. return pump("next", value);
  35. };
  36. if (typeof inner.throw === "function") {
  37. iter.throw = function (value) {
  38. if (waiting) {
  39. waiting = false;
  40. throw value;
  41. }
  42. return pump("throw", value);
  43. };
  44. }
  45. if (typeof inner.return === "function") {
  46. iter.return = function (value) {
  47. return pump("return", value);
  48. };
  49. }
  50. return iter;
  51. };