pool 1.5.3 copy "pool: ^1.5.3" to clipboard
pool: ^1.5.3 copied to clipboard

Manage a finite pool of resources. Useful for controlling concurrent file system or network requests.

example/example.dart

// Copyright (c) 2026, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:pool/pool.dart';

void main() async {
  // Create a pool that allows at most 3 concurrent resources.
  final pool = Pool(3);

  try {
    print('Starting tasks with pool size of 3...');

    // Use pool.forEach to process a list of items concurrently.
    // This is useful for limiting concurrent network requests or file I/O.
    final items = List.generate(10, (i) => i);

    await for (final result in pool.forEach(items, (item) async {
      print('  [Start] Processing item $item');
      // Simulate some async work like a network request.
      await Future<void>.delayed(const Duration(milliseconds: 100));
      print('  [Done]  Processing item $item');
      return 'Result for $item';
    })) {
      print('Processed: $result');
    }

    print('All tasks completed!');
  } finally {
    // Close the pool.
    await pool.close();
  }
}
131
likes
160
points
10.3M
downloads

Documentation

API reference

Publisher

verified publishertools.dart.dev

Weekly Downloads

Manage a finite pool of resources. Useful for controlling concurrent file system or network requests.

Repository (GitHub)
View/report issues
Contributing

License

BSD-3-Clause (license)

Dependencies

async, stack_trace

More

Packages that depend on pool