Skip to main content
Home

Built and signed on GitHub Actions

latest

Constrain any operation to complete within a certain time.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 months ago (0.1.1)

Timebox

Constrain any operation to complete within a certain time.


Very often you want to put a limit on how long an operation may run such as a fetch() of an external resource, or handling a web request. To do this, you can use the timebox() function. It will encapsulate the operation and either return its result, or a otherwise a "timeout" object indicating that it did not complete in the required time.

import { timebox } from "@effectionx/timebox";
import { handleRequest } from "./handle-request";

// a theoretical request handler
export function* handler(request) {
  // do not let the handler run for more than 10 seconds
  let result = yield* timebox(10000, () => handleRequest(request));
  if (result.timeout) {
    return new Response(504, "Gateway Timeout");
  } else {
    return result.value;
  }
}
Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@effectionx/timebox

Import symbol

import * as timebox from "@effectionx/timebox";
or

Import directly with a jsr specifier

import * as timebox from "jsr:@effectionx/timebox";

Add Package

pnpm i jsr:@effectionx/timebox
or (using pnpm 10.8 or older)
pnpm dlx jsr add @effectionx/timebox

Import symbol

import * as timebox from "@effectionx/timebox";

Add Package

yarn add jsr:@effectionx/timebox
or (using Yarn 4.8 or older)
yarn dlx jsr add @effectionx/timebox

Import symbol

import * as timebox from "@effectionx/timebox";

Add Package

vlt install jsr:@effectionx/timebox

Import symbol

import * as timebox from "@effectionx/timebox";

Add Package

npx jsr add @effectionx/timebox

Import symbol

import * as timebox from "@effectionx/timebox";

Add Package

bunx jsr add @effectionx/timebox

Import symbol

import * as timebox from "@effectionx/timebox";