Remix Utils - v9.3.1
    Preparing search index...

    Module Common/Timers

    Note

    Install using bunx shadcn@latest add @remix-utils/timers.

    The timers utils gives you a way to wait a certain amount of time before doing something or to run some code every certain amount of time.

    Using the interval combined with eventStream we could send a value to the client every certain amount of time. And ensure the interval is cancelled if the connection is closed.

    import { eventStream } from "remix-utils/sse/server";
    import { interval } from "remix-utils/timers";

    export async function loader({ request }: Route.LoaderArgs) {
    return eventStream(request.signal, function setup(send) {
    async function run() {
    for await (let _ of interval(1000, { signal: request.signal })) {
    send({ event: "time", data: new Date().toISOString() });
    }
    }

    run();
    });
    }

    Classes

    TimersError

    Functions

    interval