Utils
Response
1/27/2026, 1:17:38 PM modified by MarvinA library to mock response
Installation
Preview
Nothing to show.
import { sleep } from "~/registry/utils/common";export function mockResponse<T>({ data, abortController, delay = 30,}: { data: T[]; abortController?: AbortController; delay?: number;}) { const readableStream = new ReadableStream({ async start(controller) { const encoder = new TextEncoder(); for (const item of data) { if (abortController?.signal.aborted) break; const chunk = `data: ${JSON.stringify(item)}\n\n`; controller.enqueue(encoder.encode(chunk)); await sleep(delay); } controller.close(); }, }); return new Response(readableStream, { headers: { "Content-Type": "text/event-stream", }, });}Git Commit History(1 commits)
fix: dep
Marvin
1月27日 13:17
b6e70fbd