Skip to content

Instantly share code, notes, and snippets.

@glitch003
Last active April 30, 2021 20:07
Show Gist options
  • Save glitch003/8c66466029c81e0736d1c26a989c02de to your computer and use it in GitHub Desktop.
Save glitch003/8c66466029c81e0736d1c26a989c02de to your computer and use it in GitHub Desktop.
for await is having issues in chrome
// server code in handler: running on nodejs
await pipe(
stream,
(source) => (async function * () {
for await (const message of source) {
console.log(' > ')
console.log(message.toString())
yield 'response'
}
})(),
stream
)
// browser client code after calling newStream that works fine
await pipe(
['testRequest'],
stream,
async (source) => {
const { value, done } = await source.next()
console.debug(`new message with iterator state done ${done}: ${value.toString()}`)
const resp = await source.next()
console.log('and after next() twice, resp is ', resp)
}
)
// browser client code after calling newStream that prints infinite loop of message: undefined
await pipe(
['testRequest'],
stream,
async (source) => {
for await (const message of source) {
console.log(`message: ${message}`)
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment