Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let caps = [];
async function* SpeedRacer() {
yield new Promise(function(resolve, reject) {
caps.push({ resolve, reject });
});
yield new Promise(function(resolve, reject) {
caps.push({ resolve, reject });
});
}
let it = SpeedRacer();
it.next().then(({ value, done }) => {
console.log(`Yield #1 is done!: { value: ${value}, done: ${done} }`);
});
it.next().then(({ value, done }) => {
console.log(`Yield #2 is done!: { value: ${value}, done: ${done} }`);
});
caps[1].resolve("Number2");
caps[0].resolve("Number1");
// If resolved in this order, should log:
// `Yield #2 is done!: { value: Number2, done: false }`
// `Yield #1 is done!: { value: Number1, done: false }`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.