-
-
Save rlemon/253578095198349a3e0e8055811a5a37 to your computer and use it in GitHub Desktop.
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
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); | |
} |
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'; | |
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