Skip to content

Instantly share code, notes, and snippets.

@nickmccurdy
Last active December 31, 2023 14:59
Show Gist options
  • Save nickmccurdy/146fa055e89cc1feedefd67666a2e8db to your computer and use it in GitHub Desktop.
Save nickmccurdy/146fa055e89cc1feedefd67666a2e8db to your computer and use it in GitHub Desktop.
RSC streaming using recursive promises https://twitter.com/shuding_/status/1681373460860108810
async function Row({ chunk }) {
const { next, value, done } = await chunk
if (done) return null
return (
<>
{value}
<Row chunk={next} />
</>
)
}
async function read(reader) {
const { value, done } = await reader.read()
return {
value,
done,
next: done ? null : read(reader)
}
}
export default async function Home() {
const { body } = await fetch('https://example.com')
return <Row chunk={read(body.getReader())} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment