You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.0 KiB

4 years ago
  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. if (typeof Symbol === "function" && Symbol.iterator) {
  16. iter[Symbol.iterator] = function () {
  17. return this;
  18. };
  19. }
  20. iter.next = function (value) {
  21. if (waiting) {
  22. waiting = false;
  23. return value;
  24. }
  25. return pump("next", value);
  26. };
  27. if (typeof inner["throw"] === "function") {
  28. iter["throw"] = function (value) {
  29. if (waiting) {
  30. waiting = false;
  31. throw value;
  32. }
  33. return pump("throw", value);
  34. };
  35. }
  36. if (typeof inner["return"] === "function") {
  37. iter["return"] = function (value) {
  38. if (waiting) {
  39. waiting = false;
  40. return value;
  41. }
  42. return pump("return", value);
  43. };
  44. }
  45. return iter;
  46. }