asyncGeneratorDelegate.js 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. export default 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. }