promise-es6babel转es5 | "use strict";
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function promiseAdd(a, b) {
return new Promise(function (resolve, reject) {
var res = a + b;
resolve(res);
});
}
function run() {
return _run.apply(this, arguments);
}
function _run() {
_run = _asyncToGenerator( regeneratorRuntime.mark(function _callee() {
var res;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
promiseAdd(1, 2).then(function (r) {
res = r;
});
case 1:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return _run.apply(this, arguments);
}
run();
| ready |
async/await-es6babel转es5 | "use strict";
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function asyncAdd(_x, _x2) {
return _asyncAdd.apply(this, arguments);
}
function _asyncAdd() {
_asyncAdd = _asyncToGenerator( regeneratorRuntime.mark(function _callee(a, b) {
var res;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
res = a + b;
return _context.abrupt("return", res);
case 2:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return _asyncAdd.apply(this, arguments);
}
function run() {
return _run.apply(this, arguments);
}
function _run() {
_run = _asyncToGenerator( regeneratorRuntime.mark(function _callee2() {
var res;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return asyncAdd(1, 2);
case 2:
res = _context2.sent;
case 3:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
return _run.apply(this, arguments);
}
run();
| ready |