MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / loader

Function loader

apps/webapp/app/routes/tests.sse.stream.ts:6–40  ·  view source on GitHub ↗
({ request }: LoaderFunctionArgs)

Source from the content-addressed store, hash-verified

4import { sse } from "~/utils/sse.server";
5
6export async function loader({ request }: LoaderFunctionArgs) {
7 const url = new URL(request.url);
8 const searchParams = Object.fromEntries(url.searchParams.entries());
9
10 const options = z
11 .object({
12 minDelay: z.coerce.number().int(),
13 maxDelay: z.coerce.number().int(),
14 undefinedProbability: z.coerce.number().min(0).max(1).default(0.1),
15 })
16 .parse(searchParams);
17
18 logger.debug("Test SSE stream", { options });
19
20 let lastSignals = calculateChangeSignals(Date.now());
21
22 return sse({
23 request,
24 run: async (send, stop) => {
25 const result = await dateForUpdates(options);
26
27 if (!result) {
28 return stop();
29 }
30
31 const newSignals = calculateChangeSignals(result);
32
33 if (lastSignals.ts !== newSignals.ts) {
34 send({ data: JSON.stringify(newSignals) });
35 }
36
37 lastSignals = newSignals;
38 },
39 });
40}
41
42async function dateForUpdates(opts: {
43 minDelay: number;

Callers

nothing calls this directly

Calls 7

sseFunction · 0.90
dateForUpdatesFunction · 0.85
parseMethod · 0.80
maxMethod · 0.80
minMethod · 0.80
calculateChangeSignalsFunction · 0.70
debugMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…