Skip to content

Instantly share code, notes, and snippets.

@brillout
Created June 19, 2026 09:21
Show Gist options
  • Select an option

  • Save brillout/155c8eb4cbaa043bc52e96c0c2ed7086 to your computer and use it in GitHub Desktop.

Select an option

Save brillout/155c8eb4cbaa043bc52e96c0c2ed7086 to your computer and use it in GitHub Desktop.

Mix freely — a telefunction can return any combination of generators, callbacks, streams, channels, and promises, nested anywhere in the returned object. Each resolves independently, without blocking the others.

// Feed.telefunc.ts
// Environment: server

export async function onLoadFeed() {
  async function* notifications(): AsyncGenerator<string> {
    for (const n of await fetchNotifications()) {
      yield n.text
    }
  }

  return {
    title: 'Feed',
    stream: notifications(),
    fast: Promise.resolve({ count: 42 }),
    slow: fetchExtensiveReport(),
  }
}
// Feed.tsx
// Environment: client

import { onLoadFeed } from './Feed.telefunc'

const res = await onLoadFeed()

// Static values — available immediately
console.log(res.title)

// Consume generator and promises independently
for await (const notification of res.stream) {
  console.log(notification)
}

const fast = await res.fast
const slow = await res.slow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment