We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v1.1.6
any
export class EventStreamWriter { #sink; static create(opts) { const writer = new EventStreamWriter() const stream = new ReadableStream({ type: 'direct', async pull(ctrl) { writer.#sink = ctrl }, }) const response = new Response(stream) return { writer, response } } write(message) { console.info('write message:', message = `event: ${message.event}\n\n`) message = new TextEncoder().encode(message) this.#sink.write(message) this.#sink.flush() } } const server = Bun.serve({ async fetch(req) { const { writer, response } = EventStreamWriter.create({}) setTimeout(async () => { let i = 3 while (i--) { writer.write({event: "hello "+ i}) await Bun.sleep(1000) } }, 1000) return response }, }) console.info(`Server started on ${server.url}`) //// TEST let response = await fetch(server.url) let chunk, reader = response.body.getReader(); console.info('[JS]', {status: response.status}) while ((chunk = await reader.read()).value) { console.info({value: new TextDecoder().decode(chunk.value).slice(0, 30)}) }
'direct' ReadableStream sink should can be extracted and use in somewhere async calls
22 | this.#sink.write(message) ^ TypeError: Expected Sink code: "ERR_INVALID_THIS"
No response
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
What version of Bun is running?
v1.1.6
What platform is your computer?
any
What steps can reproduce the bug?
What is the expected behavior?
'direct' ReadableStream sink should can be extracted and use in somewhere async calls
What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: