Skip to content

Instantly share code, notes, and snippets.

@FlyingDR
Created July 18, 2018 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlyingDR/532e6f38393317d0d4bebfa9fc1acca9 to your computer and use it in GitHub Desktop.
Save FlyingDR/532e6f38393317d0d4bebfa9fc1acca9 to your computer and use it in GitHub Desktop.
Discovery of async/await internals
{
"name": "test-async",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"babel": {
"presets": [
[
"env",
{
"targets": {
"node": "4.0"
}
}
]
]
},
"dependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0"
}
}
"use strict";
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
var foo = function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return bar();
case 2:
return _context.abrupt("return", _context.sent);
case 3:
case "end":
return _context.stop();
}
}
}, _callee, undefined);
}));
return function foo() {
return _ref.apply(this, arguments);
};
}();
var bar = function bar() {
return new Promise(function (resolve) {
return setTimeout(function () {
return resolve();
}, 100);
});
};
const foo = async () => await bar();
const bar = () => new Promise(resolve => setTimeout(() => resolve(), 100));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment