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