import { WebComponent, html, signal } from '@webjsdev/core'; import { streamTokens } from '#modules/verbdemo/actions/stream-tokens.server.ts'; /** * ``: the streaming-RPC demo (#489). Clicking "start" calls the * `streamTokens` async-generator action and appends each token as it arrives, so * the list grows incrementally rather than all at once. This is the imperative * `for await` consumption pattern (the action returns an async iterable over RPC, * not a single buffered value). The e2e asserts the rendered count climbs. */ export class TokenStream extends WebComponent { readonly #tokens = signal([]); readonly #streaming = signal(false); private async start() { this.#tokens.set([]); this.#streaming.set(true); try { for await (const tok of await streamTokens(8)) { this.#tokens.set([...this.#tokens.get(), tok]); } } finally { this.#streaming.set(false); } } render() { const toks = this.#tokens.get(); return html`
count=${toks.length}
    ${toks.map((t) => html`
  • ${t}
  • `)}
`; } } TokenStream.register('token-stream');