Skip to content

feat: add throttle function and @throttle decorator #72

Description

@tabkram

Goal

Add a throttle() function and @throttle() method decorator for sync and async functions.

const fetchProfile = throttle(
  async (userId: string) => api.getProfile(userId),
  { limit: 3, interval: 1_000 }
);

Scope

  • Configurable limit and interval
  • leading / trailing behavior
  • Preserve this, arguments, return type and errors
  • Per-instance state for decorated instance methods
  • AbortSignal, cancel(), and queue-size visibility
  • Unit tests and documentation

Trace integration

Record delayed, executed, cancelled, and rejected calls in the engine trace.

Acceptance criteria

  • Supports synchronous and Promise-returning functions
  • Concurrent callers retain their original arguments and receive the correct outcome
  • Decorator state is isolated per class instance
  • Public API is exported from the package entry point

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions