Skip to content
oRPC
Esc
navigateopen⌘Jpreview
On this page

v1.8.8

consumeEventIterator utility docs

oRPC provides a utility function consumeEventIterator to consume an event iterator with lifecycle callbacks.

import { consumeEventIterator } from '@orpc/client'

const cancel = consumeEventIterator(client.streaming(), {
  onEvent: (event) => {
    console.log(event.message)
  },
  onError: (error) => {
    console.error(error)
  },
  onSuccess: (value) => {
    console.log(value)
  },
  onFinish: (state) => {
    console.log(state)
  },
})

setTimeout(async () => {
  // Stop the stream after 1 second
  await cancel()
}, 1000)

optimize withEventMeta to avoid unnecessary proxies event iterator data

This prevents structuredClone from failing on proxy event iterator data, which the AI SDKdepends on.

const { messages, sendMessage, status } = useChat({
  transport: {
    async sendMessages(options) {
      return eventIteratorToStream(await client.chat({
        chatId: options.chatId,
        messages: options.messages,
      }, { signal: options.abortSignal }))
    },
    reconnectToStream(options) {
      throw new Error('Unsupported')
    },
  },
})

[!NOTE] If you find oRPC valuable and would like to support its development, you can do so here.

   🚀 Features

   🐞 Bug Fixes

    View changes on GitHub

Last updated on September 11, 2025

Was this page helpful?