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.

36 lines
809 B

4 years ago
  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;