github unnoq/orpc v1.4.2

latest releases: v1.8.7, v1.8.6, v1.8.5...
3 months ago

EventPublisher utility

oRPC includes a built-in EventPublisher for real-time features like chat, notifications, or live updates. It supports broadcasting and subscribing to named events. docs

import { EventPublisher } from '@orpc/server'

const publisher = new EventPublisher<Record<string, { message: string }>>()

const onMessage = os
  .input(z.object({ channel: z.string() }))
  .handler(async function* ({ input, signal }) {
    for await (const payload of publisher.subscribe(input.channel, { signal })) { 
      yield payload.message
    }
  })

const sendMessage = os
  .input(z.object({ channel: z.string(), message: z.string() }))
  .handler(({ input }) => {
    publisher.publish(input.channel, { message: input.message }) 
  })

   🚀 Features

    View changes on GitHub

Don't miss a new orpc release

NewReleases is sending notifications on new releases.