asyncToGenerator.js 887 B

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