Skip to Content
Senri

Timeout

Return 504 with timeout() if a request does not finish in time

import { ,  } from "@senrijs/senri";

const  = ();

.("/api", (5000));   // 504 if not finished in 5 seconds

What it does not stop

Even after it returns 504, the handler's work itself does not stop.

  • During a synchronous loop, the timer does not run either
  • c.req.signal only means the client disconnected
  • To stop calls to other services, combine it with AbortSignal.timeout()
.("/api", (5000));
.("/api/slow", async () => {
    const  = await ("https://example.com/slow", { : .(5000) });
    return .();
});

Options

Prop

Type

On this page