Skip to content

Instantly share code, notes, and snippets.

@jooyunghan
Created December 20, 2017 15:10
Show Gist options
  • Save jooyunghan/9d6ecfb25f683e63ddf5c2b870ba818e to your computer and use it in GitHub Desktop.
Save jooyunghan/9d6ecfb25f683e63ddf5c2b870ba818e to your computer and use it in GitHub Desktop.
function createAsyncIterator() {
const promises = [];
this.subscribe({
next(value) {
promises.shift().resolve({ value, done: false });
}
});
return {
next() {
return new Promise((resolve, reject) => {
promises.push({ resolve, reject });
});
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment