limitFunction<T> function

LimitedFunctionWrapper<T> limitFunction<T>(
  1. Future<T> function(),
  2. LimitOptions options
)

Create a limited version of a function

Returns a wrapped version of function that respects the concurrency limits specified in options.

Example:

Future<String> fetchData() async {
  return await http.get('https://api.example.com');
}

final limitedFetch = limitFunction(
  fetchData,
  LimitOptions(concurrency: 5),
);

// All calls respect the 5-concurrent limit
final results = await Future.wait([
  limitedFetch(),
  limitedFetch(),
  limitedFetch(),
]);

Implementation

LimitedFunctionWrapper<T> limitFunction<T>(
  Future<T> Function() function,
  LimitOptions options,
) {
  final limit =
      FLimit(options.concurrency, queueStrategy: options.queueStrategy);
  return () => limit(function);
}