Last active
April 30, 2021 20:07
-
-
Save glitch003/8c66466029c81e0736d1c26a989c02de to your computer and use it in GitHub Desktop.
for await is having issues in chrome
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
// 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