Skip to content

Instantly share code, notes, and snippets.

@tylermcginnis
Created February 13, 2016 19:16
Show Gist options
  • Save tylermcginnis/1b9af15fa007d47da5a8 to your computer and use it in GitHub Desktop.
Save tylermcginnis/1b9af15fa007d47da5a8 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<!-- put markup and other contents here -->
</body>
</html>
function doAsyncThing () {
console.log('Kicking off')
return new Promise((res, rej) => {
setTimeout(() => res('hi'), 1000)
})
}
async function doThing () {
var val = await doAsyncThing()
return val
}
doThing().then((res) => {
console.log(res)
})
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"babel-runtime": "6.3.19"
}
}
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function doAsyncThing() {
console.log('Kicking off');
return new _promise2.default(function (res, rej) {
setTimeout(function () {
return res('hi');
}, 1000);
});
}
var doThing = (function () {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() {
var val;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return doAsyncThing();
case 2:
val = _context.sent;
return _context.abrupt('return', val);
case 4:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
return function doThing() {
return ref.apply(this, arguments);
};
})();
doThing().then(function (res) {
console.log(res);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment