flutter_debounce_throttle_core 1.1.0
flutter_debounce_throttle_core: ^1.1.0 copied to clipboard
Pure Dart debounce, throttle, and rate limiting. Zero dependencies, works everywhere - Mobile, Web, Desktop, Server, CLI.
flutter_debounce_throttle_core #
Pure Dart Event Control — Zero Dependencies
Production-ready debounce, throttle, and rate limiting for Dart servers, CLI tools, and any platform.
// Simple, safe, powerful
final debouncer = Debouncer(duration: 300.ms);
debouncer(() => search(query));
Why This Package? #
- Zero dependencies — only
metapackage - Server-ready — no Flutter required
- Type-safe — full generic support
- Battle-tested — 340+ tests
Installation #
dependencies:
flutter_debounce_throttle_core: ^1.1.0
Quick Start #
Throttle (Rate Limit) #
final throttler = Throttler(duration: Duration(milliseconds: 500));
throttler(() => processRequest());
Debounce (Wait for Pause) #
final debouncer = Debouncer(duration: Duration(milliseconds: 300));
debouncer(() => search(query));
Async with Cancellation #
final asyncDebouncer = AsyncDebouncer(duration: 300.ms);
final result = await asyncDebouncer(() async => await api.search(query));
if (result != null) updateUI(result);
Token Bucket Rate Limiting #
final limiter = RateLimiter(
maxTokens: 100, // Burst capacity
refillRate: 10, // 10 tokens/second
refillInterval: 1.seconds,
);
if (limiter.tryAcquire()) {
await processRequest();
} else {
return Response.tooManyRequests(
retryAfter: limiter.timeUntilNextToken,
);
}
Batch Operations #
final batcher = BatchThrottler(
duration: 1.seconds,
maxBatchSize: 100,
onBatchExecute: (actions) async {
final logs = actions.map((a) => a()).toList();
await database.insertBatch(logs);
},
);
// 1000 log calls → 10 database writes
batcher(() => 'User logged in');
batcher(() => 'Page viewed');
Complete Toolkit #
| Class | Use Case |
|---|---|
Throttler |
Rate limiting, spam prevention |
Debouncer |
Search input, form validation |
AsyncThrottler |
Async operations with timeout |
AsyncDebouncer |
Auto-cancel stale async calls |
ConcurrentAsyncThrottler |
4 concurrency modes |
HighFrequencyThrottler |
60fps events (no Timer overhead) |
BatchThrottler |
Batch database writes |
RateLimiter |
Token Bucket algorithm |
Concurrency Modes:
ConcurrentAsyncThrottler(mode: ConcurrencyMode.drop) // Ignore while busy
ConcurrentAsyncThrottler(mode: ConcurrencyMode.replace) // Cancel old, run new
ConcurrentAsyncThrottler(mode: ConcurrencyMode.enqueue) // Queue in order
ConcurrentAsyncThrottler(mode: ConcurrencyMode.keepLatest) // Current + last only
v1.1.0 Features #
// Duration extensions
300.ms // Duration(milliseconds: 300)
2.seconds // Duration(seconds: 2)
5.minutes // Duration(minutes: 5)
// Callback extensions
final debouncedFn = myFunction.debounced(300.ms);
final throttledFn = myFunction.throttled(500.ms);
// Leading + trailing edge (like lodash)
Debouncer(leading: true, trailing: true)
// Overflow strategies
BatchThrottler(maxBatchSize: 50, overflowStrategy: BatchOverflowStrategy.dropOldest)
ConcurrentAsyncThrottler(maxQueueSize: 10, queueOverflowStrategy: QueueOverflowStrategy.dropNewest)
Related Packages #
| Package | Use When |
|---|---|
| flutter_debounce_throttle | Flutter apps |
| flutter_debounce_throttle_hooks | Flutter + Hooks |