Skip to content

Instantly share code, notes, and snippets.

@rlemon

rlemon/a.js Secret

Created April 24, 2017 20:28
Show Gist options
  • Save rlemon/253578095198349a3e0e8055811a5a37 to your computer and use it in GitHub Desktop.
Save rlemon/253578095198349a3e0e8055811a5a37 to your computer and use it in GitHub Desktop.
import 'regenerator-runtime/runtime';
import Promise from 'bluebird';
function doSomethingAsync(value) {
return new Promise((resolve, reject) => {
resolve(value);
});
}
async function foo() {
const value = await doSomethingAsync(123);
console.log(value);
}
'use strict';
var _bluebird = require('bluebird');
var _bluebird2 = _interopRequireDefault(_bluebird);
var foo = function () {
var _ref = (0, _bluebird.coroutine)(regeneratorRuntime.mark(function _callee() {
var value;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return doSomethingAsync(123);
case 2:
value = _context.sent;
console.log(value);
case 4:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
return function foo() {
return _ref.apply(this, arguments);
};
}();
require('regenerator-runtime/runtime'); // <--- this needs to be at the top of the file to inject the global regeneratorRuntime. babel moves it.
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function doSomethingAsync(value) {
return new _bluebird2.default(function (resolve, reject) {
resolve(value);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment