pool 1.3.3

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 96

The pool package exposes a Pool class which makes it easy to manage a limited pool of resources.

The easiest way to use a pool is by calling withResource. This runs a callback and returns its result, but only once there aren't too many other callbacks currently running.

// Create a Pool that will only allocate 10 resources at once. After 30 seconds
// of inactivity with all resources checked out, the pool will throw an error.
final pool = new Pool(10, timeout: new Duration(seconds: 30));

Future<String> readFile(String path) {
  // Since the call to [File.readAsString] is within [withResource], no more
  // than ten files will be open at once.
  return pool.withResource(() => new File(path).readAsString());
}

For more fine-grained control, the user can also explicitly request generic PoolResource objects that can later be released back into the pool. This is what withResource does under the covers: requests a resource, then releases it once the callback completes.

Pool ensures that only a limited number of resources are allocated at once. It's the caller's responsibility to ensure that the corresponding physical resource is only consumed when a PoolResource is allocated.

class PooledFile implements RandomAccessFile {
  final RandomAccessFile _file;
  final PoolResource _resource;

  static Future<PooledFile> open(String path) {
    return pool.request().then((resource) {
      return new File(path).open().then((file) {
        return new PooledFile._(file, resource);
      });
    });
  }

  PooledFile(this._file, this._resource);

  // ...

  Future<RandomAccessFile> close() {
    return _file.close.then((_) {
      _resource.release();
      return this;
    });
  }
}

1.3.3

  • Declare support for async 2.0.0.

1.3.2

  • Update to make the code work with strong-mode clean Zone API.

  • Required minimum SDK of 1.23.0.

1.3.1

  • Fix the type annotation of Pool.withResource() to indicate that it takes () -> FutureOr<T>.

1.3.0

  • Add a Pool.done getter that returns the same future returned by Pool.close().

1.2.4

  • Fix a strong-mode error.

1.2.3

  • Fix a bug in which Pool.withResource() could throw a StateError when called immediately before closing the pool.

1.2.2

  • Fix strong mode warnings and add generic method annotations.

1.2.1

  • Internal changes only.

1.2.0

  • Add Pool.close(), which forbids new resource requests and releases all releasable resources.

1.1.0

  • Add PoolResource.allowRelease(), which allows a resource to indicate that it can be released without forcing it to deallocate immediately.

1.0.2

  • Fixed the homepage.

1.0.1

  • A TimeoutException is now correctly thrown if the pool detects a deadlock.

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  pool: "^1.3.3"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:pool/pool.dart';
        
Version Uploaded Documentation Archive
1.3.3 Sep 22, 2017 Go to the documentation of pool 1.3.3 Download pool 1.3.3 archive
1.3.2 Sep 21, 2017 Go to the documentation of pool 1.3.2 Download pool 1.3.2 archive
1.3.1 May 17, 2017 Go to the documentation of pool 1.3.1 Download pool 1.3.1 archive
1.3.0 Feb 16, 2017 Go to the documentation of pool 1.3.0 Download pool 1.3.0 archive
1.2.4 May 3, 2016 Go to the documentation of pool 1.2.4 Download pool 1.2.4 archive
1.2.3 Apr 4, 2016 Go to the documentation of pool 1.2.3 Download pool 1.2.3 archive
1.2.2 Mar 31, 2016 Go to the documentation of pool 1.2.2 Download pool 1.2.2 archive
1.2.1 Oct 28, 2015 Go to the documentation of pool 1.2.1 Download pool 1.2.1 archive
1.2.0 Oct 9, 2015 Go to the documentation of pool 1.2.0 Download pool 1.2.0 archive
1.1.0 Jun 24, 2015 Go to the documentation of pool 1.1.0 Download pool 1.1.0 archive

All 13 versions...

Analysis

This feature is new.
We welcome feedback.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Dec 6, 2017
  • Dart: 2.0.0-dev.8.0
  • pana: 0.7.3+1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
92
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall score:
Weighted score of the above. [more]
96

Platforms

Detected platforms: Flutter, server, web

All libraries agree

Dependencies

Package Constraint Resolved Available
Direct dependencies
async >=1.4.0 <3.0.0 2.0.1
stack_trace >=0.9.2 <2.0.0 1.9.1
Transitive dependencies
collection 1.14.3
path 1.5.1
Dev dependencies
fake_async >=0.1.0 <0.2.0
test >=0.12.0 <0.13.0