FLimit class
A concurrency limiter that controls how many async operations can run simultaneously
Example:
final limit = fLimit(2); // Max 2 concurrent operations
// Execute with limit
final result = await limit(() async {
return fetchData();
});
// With priority (when using priority strategy)
final limit = fLimit(1, queueStrategy: QueueStrategy.priority);
limit(() async => print('low'), priority: 1);
limit(() async => print('high'), priority: 10);
- Available extensions
Constructors
- FLimit(int concurrency, {QueueStrategy queueStrategy = QueueStrategy.fifo})
- Creates a concurrency limiter
Properties
- activeCount → int
-
Current number of active operations
no setter
- concurrency ↔ int
-
Current concurrency limit
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- isBusy → bool
-
Whether there are any active tasks
no setter
- isClosed → bool
-
Whether the limiter has been closed.
no setter
- isEmpty → bool
-
Whether there are no active or pending tasks
no setter
- isPaused → bool
-
Whether the limiter is paused
no setter
-
onIdle
→ Future<
void> -
Returns a Future that completes when the queue is empty and active count is 0.
no setter
- pendingCount → int
-
Current number of pending operations in the queue
no setter
- queueStrategy → QueueStrategy
-
Current queue strategy
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
call<
T> (Future< T> function(), {int priority = 0, Duration? timeout, RetryPolicy? retry, TaskTimeouts? timeouts}) → TaskHandle<T> - Execute a function with concurrency limit
-
clearQueue(
) → int - Clear all pending operations from the queue
-
close(
{bool cancelPending = true}) → Future< void> - Closes the limiter to new work and waits until it becomes idle.
-
dispose(
{bool cancelPending = true}) → Future< void> - Alias for close.
-
filter<
Item> (Iterable< Item> items, Future<bool> predicate(Item item), {int priority = 0, Duration? timeout, RetryPolicy? retry, TaskTimeouts? timeouts}) → Future<List< Item> > -
Available on FLimit, provided by the FLimitExtensions extension
Filtersitemsconcurrently using thepredicatefunction. -
forEach<
Item> (Iterable< Item> items, Future<void> action(Item item), {int priority = 0, Duration? timeout, RetryPolicy? retry, TaskTimeouts? timeouts}) → Future<void> -
Available on FLimit, provided by the FLimitExtensions extension
Executesactionfor each item initemsconcurrently with the concurrency limit. -
forEachSettled<
Item> (Iterable< Item> items, Future<void> action(Item item), {int priority = 0, Duration? timeout, RetryPolicy? retry, TaskTimeouts? timeouts}) → Future<List< SettledResult< >void> > -
Available on FLimit, provided by the FLimitExtensions extension
Executesactionfor each item and returns settled outcomes. -
isolate<
T> (FutureOr< T> computation(), {int priority = 0, Duration? timeout, TaskTimeouts? timeouts, RetryPolicy? retry}) → TaskHandle<T> -
Available on FLimit, provided by the FLimitIsolate extension
Executes a computation in a separate isolate with concurrency limit -
map<
Item, Result> (Iterable< Item> items, Future<Result> mapper(Item item), {int priority = 0, Duration? timeout, RetryPolicy? retry, TaskTimeouts? timeouts}) → Future<List< Result> > -
Available on FLimit, provided by the FLimitExtensions extension
Maps theitemsto futures using themapperfunction, respecting the concurrency limit. -
mapIndexed<
Item, Result> (Iterable< Item> items, Future<Result> mapper(int index, Item item), {int priority = 0, Duration? timeout, RetryPolicy? retry, TaskTimeouts? timeouts}) → Future<List< Result> > -
Available on FLimit, provided by the FLimitExtensions extension
Executes tasks and collects results with their indices. -
mapSettled<
Item, Result> (Iterable< Item> items, Future<Result> mapper(Item item), {int priority = 0, Duration? timeout, RetryPolicy? retry, TaskTimeouts? timeouts}) → Future<List< SettledResult< >Result> > -
Available on FLimit, provided by the FLimitExtensions extension
Mapsitemsand captures both successes and failures without throwing. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pause(
) → void - Pause the limiter
-
reduce<
Item> (Iterable< Item> items, Future<Item> combine(Item a, Item b), {int priority = 0, Duration? timeout, RetryPolicy? retry, TaskTimeouts? timeouts}) → Future<Item> -
Available on FLimit, provided by the FLimitExtensions extension
Reducesitemsto a single value usingcombinefunction. -
resume(
) → void - Resume the limiter
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited