DEV Community

Avinash
Avinash

Posted on

flowx-control: TypeScript Flow Control (Debounce, Throttle, RateLimit) for Modern Apps

Ever struggled with UI freezing on every keystroke or APIs getting hammered with duplicate calls? flowx-control solves exactly that.

What is flowx-control?

A zero-dependency TypeScript library that gives you precise control over function execution timing. Debounce, throttle, rate-limit, and more — all type-safe and tree-shakeable.

npm install flowx-control
bun add flowx-control
Enter fullscreen mode Exit fullscreen mode

Core Features

Debounce

Delay execution until after calls stop:

import { debounce } from 'flowx-control';

const search = debounce(async (query: string) => {
  const results = await api.search(query);
  updateUI(results);
}, 300);

// Only fires 300ms after user stops typing
input.addEventListener('input', (e) => search(e.target.value));
Enter fullscreen mode Exit fullscreen mode

Throttle

Limit execution to once per interval:

import { throttle } from 'flowx-control';

const onScroll = throttle(() => {
  updateScrollPosition();
}, 100);

window.addEventListener('scroll', onScroll);
Enter fullscreen mode Exit fullscreen mode

Rate Limit

Control how many calls per time window:

import { rateLimit } from 'flowx-control';

const apiCall = rateLimit(fetchData, {
  maxCalls: 10,
  windowMs: 1000 // 10 calls per second
});
Enter fullscreen mode Exit fullscreen mode

Once

Execute only on first call:

import { once } from 'flowx-control';

const init = once(() => {
  setupDatabase();
  loadConfig();
});

init(); // runs
init(); // skipped
Enter fullscreen mode Exit fullscreen mode

Why flowx-control?

  • Zero dependencies
  • Full TypeScript support with generics
  • Works in Node.js, Bun, Deno, browsers, and edge runtimes
  • Tiny bundle size
  • Cancellable and flushable debounces

Works Everywhere

Tree-shakeable, dual ESM/CJS output. Drop it into any modern stack.

GitHub: https://github.com/Avinashvelu03/flowx-control

What flow control patterns do you use in your TypeScript projects?

Top comments (0)