asyncGeneratorDelegate.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. function _asyncGeneratorDelegate(inner, awaitWrap) {
  2. var iter = {},
  3. waiting = false;
  4. function pump(key, value) {
  5. waiting = true;
  6. value = new Promise(function (resolve) {
  7. resolve(inner[key](value));
  8. });
  9. return {
  10. done: false,
  11. value: awaitWrap(value)
  12. };
  13. }
  14. ;
  15. iter[typeof Symbol !== "undefined" && Symbol.iterator || "@@iterator"] = function () {
  16. return this;
  17. };
  18. iter.next = function (value) {
  19. if (waiting) {
  20. waiting = false;
  21. return value;
  22. }
  23. return pump("next", value);
  24. };
  25. if (typeof inner["throw"] === "function") {
  26. iter["throw"] = function (value) {
  27. if (waiting) {
  28. waiting = false;
  29. throw value;
  30. }
  31. return pump("throw", value);
  32. };
  33. }
  34. if (typeof inner["return"] === "function") {
  35. iter["return"] = function (value) {
  36. if (waiting) {
  37. waiting = false;
  38. return value;
  39. }
  40. return pump("return", value);
  41. };
  42. }
  43. return iter;
  44. }
  45. module.exports = _asyncGeneratorDelegate, module.exports.__esModule = true, module.exports["default"] = module.exports;