_async_to_generator.js 980 B

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _asyncToGenerator;
  6. function _asyncToGenerator(fn) {
  7. return function() {
  8. var self = this, args = arguments;
  9. return new Promise(function(resolve, reject) {
  10. var gen = fn.apply(self, args);
  11. function _next(value) {
  12. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  13. }
  14. function _throw(err) {
  15. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  16. }
  17. _next(undefined);
  18. });
  19. };
  20. }
  21. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  22. try {
  23. var info = gen[key](arg);
  24. var value = info.value;
  25. } catch (error) {
  26. reject(error);
  27. return;
  28. }
  29. if (info.done) {
  30. resolve(value);
  31. } else {
  32. Promise.resolve(value).then(_next, _throw);
  33. }
  34. }