-
-
Save FlyingDR/532e6f38393317d0d4bebfa9fc1acca9 to your computer and use it in GitHub Desktop.
Discovery of async/await internals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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