asyncToGenerator.js 906 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. exports.__esModule = true;
  3. var _promise = require("../core-js/promise");
  4. var _promise2 = _interopRequireDefault(_promise);
  5. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  6. exports.default = function (fn) {
  7. return function () {
  8. var gen = fn.apply(this, arguments);
  9. return new _promise2.default(function (resolve, reject) {
  10. function step(key, arg) {
  11. try {
  12. var info = gen[key](arg);
  13. var value = info.value;
  14. } catch (error) {
  15. reject(error);
  16. return;
  17. }
  18. if (info.done) {
  19. resolve(value);
  20. } else {
  21. return _promise2.default.resolve(value).then(function (value) {
  22. step("next", value);
  23. }, function (err) {
  24. step("throw", err);
  25. });
  26. }
  27. }
  28. return step("next");
  29. });
  30. };
  31. };