Last active
July 1, 2019 02:53
-
-
Save kunigami/f0a678998b2231697012d3f840f14b6e 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
function _asyncToGenerator(fn) { | |
return function () { | |
var self = this; | |
var args = arguments; | |
return new Promise(function (resolve, reject) { | |
// Instantiates the generator | |
var gen = fn.apply(self, args); | |
function _next(value) { | |
// Next step of the generator | |
var info = gen.next(value); | |
var newValue = info.value; | |
if (info.done) { | |
resolve(newValue); | |
} else { | |
newValue.then(_next); | |
} | |
} | |
// Calls the generator recursively until it's done | |
_next(undefined); | |
}); | |
}; | |
} | |
function f1() { | |
return Promise.resolve(21); | |
} | |
function f2(x) { | |
return Promise.resolve(x * 2); | |
} | |
function g() { | |
_g = _asyncToGenerator(function* () { | |
r = yield f1(); | |
s = yield f2(r); | |
return s; | |
}); | |
return _g.apply(this, arguments); | |
} | |
g().then(r => console.log(r)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment