Skip to content

Instantly share code, notes, and snippets.

@nanot1m
Last active October 17, 2017 20:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nanot1m/6252e732667f4048790efd47198258dd to your computer and use it in GitHub Desktop.
Save nanot1m/6252e732667f4048790efd47198258dd to your computer and use it in GitHub Desktop.
Push iterator
async function* MessagesGenerator() {
try {
while (true) {
// listenToNewMessages: (message => void) => void
yield await new Promise(listenToNewMessages);
}
}
}
const messages = MessagesGenerator()
for await (let message of messages)) {
console.log(message)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment