Skip to main content
Home

Built and signed on GitHub Actions

latest

Rate limit the number of concurrent tasks in Effection programs.

This package works with Node.js, Deno, Bun, BrowsersIt is unknown whether this package works with Cloudflare Workers
It is unknown whether 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 (1.0.2)

Task Buffer

Manages concurrent task execution by enforcing a maximum limit on simultaneously active operations.


When this limit is reached, the TaskBuffer automatically queues additional spawn requests and processes them in order as capacity becomes available. This prevents resource overload while ensuring all tasks are eventually executed.

import { run, sleep } from "effection";
import { useTaskBuffer } from "@effectionx/task-buffer";

await run(function* () {
  // Create a task buffer with a maximum of 2 concurrent tasks
  const buffer = yield* useTaskBuffer(2);

  // These tasks will execute immediately since they're within the limit
  yield* buffer.spawn(() => sleep(10));
  yield* buffer.spawn(() => sleep(10));

  // This task will be queued until one of the running tasks completes
  yield* buffer.spawn(() => sleep(10));

  // Wait for this specific task to complete
  yield* yield* buffer.spawn(() => sleep(10));

  // Wait for all spawned tasks to complete
  yield* buffer;
});
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/task-buffer

Import symbol

import * as task_buffer from "@effectionx/task-buffer";
or

Import directly with a jsr specifier

import * as task_buffer from "jsr:@effectionx/task-buffer";

Add Package

pnpm i jsr:@effectionx/task-buffer
or (using pnpm 10.8 or older)
pnpm dlx jsr add @effectionx/task-buffer

Import symbol

import * as task_buffer from "@effectionx/task-buffer";

Add Package

yarn add jsr:@effectionx/task-buffer
or (using Yarn 4.8 or older)
yarn dlx jsr add @effectionx/task-buffer

Import symbol

import * as task_buffer from "@effectionx/task-buffer";

Add Package

vlt install jsr:@effectionx/task-buffer

Import symbol

import * as task_buffer from "@effectionx/task-buffer";

Add Package

npx jsr add @effectionx/task-buffer

Import symbol

import * as task_buffer from "@effectionx/task-buffer";

Add Package

bunx jsr add @effectionx/task-buffer

Import symbol

import * as task_buffer from "@effectionx/task-buffer";