Reputation: 100381
Can I have an endpoint that answers with stream?
export const chatRouter = createTRPCRouter({
// placeholder; in the future this will be an API call to an AI endpoint
chat: protectedProcedure.query(async function* () {
for (let i = 0; i < 3; i++) {
await new Promise((resolve) => setTimeout(resolve, 500));
yield i;
}
}),
})
How do I consume it in the frontend?
import { api } from "@/trpc/react";
api.chat.chat.consumeStreamEndpoint?
Upvotes: 0
Views: 29