p-hatan/ mirror

pub repository

mirror.p-hatan.ir

pool

1.5.1

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

Download archive

Readme

Dart CI pub package package publisher

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;
    });
  }
}
Changelog

1.5.1

  • Switch to using package:lints for analysis.
  • Populate the pubspec repository field.

1.5.0

  • Stable release for null safety.

1.5.0-nullsafety.3

  • Update SDK constraints to >=2.12.0-0 <3.0.0 based on beta release guidelines.

1.5.0-nullsafety.2

  • Allow prerelease versions of the 2.12 sdk.

1.5.0-nullsafety.1

  • Allow 2.10 stable and 2.11.0 dev SDK versions.

1.5.0-nullsafety

  • Migrate to null safety.
  • forEach: Avoid await null if the Stream is not paused. Improves trivial benchmark by 40%.

1.4.0

  • Add forEach to Pool to support efficient async processing of an Iterable.

  • Throw ArgumentError if poolSize <= 0

1.3.6

  • Set max SDK version to <3.0.0, and adjust other dependencies.

1.3.5

  • Updated SDK version to 2.0.0-dev.17.0

1.3.4

  • Modify code to eliminate Future flattening.

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.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add pool
pubspec.yaml
name: pool
version: 1.5.1
description: >-
  Manage a finite pool of resources.
  Useful for controlling concurrent file system or network requests.
repository: https://github.com/dart-lang/pool

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  async: ^2.5.0
  stack_trace: ^1.10.0

dev_dependencies:
  fake_async: ^1.2.0
  lints: ^1.0.0
  test: ^1.16.0

Version history

VersionPublishedArchiveSHA-256
1.0.02014-07-24T00:26:45.514990ZDownload465486caca9ed81e493e439e0647fcbcfd24596c64a4ca19c56029ea901e6617
1.0.12014-07-24T20:29:49.339400ZDownloadbddb6031a7107265e5fd5cf7cdfbd78a5549aa7733eddc60d8b20ffe177b00a8
1.0.22015-05-23T01:46:07.653ZDownload99c7862d0f132fcf6c4d8ca0df5e765644706d779a81bddee2b62a6c976cf267
1.1.02015-06-24T22:05:06.605ZDownload4b948db046cc34eb4a75b0a7ab68b126a166f349ee6a35d4f5209b097699f458
1.2.02015-10-09T00:46:54.027ZDownload8bd4bcd8e9be1d302852ecda589a86d4c9d0531165cdedc6707ac36864ec35ca
1.2.12015-10-28T21:47:53.594ZDownload9031d5b75a72d3eef80d3193d39245076836d0ad6b9b8ef998f76a54825648b6
1.2.22016-03-31T23:48:56.060ZDownload48ae768fbf8dbaec84d741634eb529a07b391e74d7c66a12bd738eda881b0286
1.2.32016-04-04T22:44:26.904ZDownload264ec1d4a12bf0cca122ed58f0659666249390c1bd33bf30b1fa271225e0e4ad
1.2.42016-05-03T23:28:03.549ZDownloadc48abab9c32a0e66293a608abaaacfa1149d304096c5a688fe81d6d7ab705c89
1.3.02017-02-16T21:10:59.980ZDownload71dbb9bdb3a0ea0b3ab19744cf267bd94e2f38c48ed2d287c78a593391480ddc
1.3.12017-05-17T03:45:18.067062ZDownloade716b5317ca6dcb9b6bf92d5c6fc941169860397aa8b61d6e2ef5855161e36d3
1.3.22017-09-21T15:52:39.565577ZDownloadbaf19276e26032dca6eb40a6cb2db46bfe4ef3cc7cc71fb94cc8b66d7735e3fd
1.3.32017-09-22T20:42:21.349569ZDownload53c4e0af70dc55cfd678c9003486de7f3e1f33635a0f86ecdfc638ee55e501fd
1.3.42018-01-04T16:25:51.076720ZDownloada6ffa8eeace0c176a21386d3fceb82261f695c29459e583014daf0fab57584b4
1.3.52018-05-18T22:34:29.099226ZDownload90f4769eeb9d983b0be9a764b877a70b00ab650c68aafa35c7866dd299d3fcfd
1.3.62018-07-20T21:46:46.644806ZDownload4ac7f0582237de67b38e08a1e643c5da81b186504e391b8ff3772ad3b7bf312a
1.4.02019-01-09T01:11:04.645539ZDownloadd5aa3ff42fe4f3a938c65f3c397895e5f888aea567ad7a5056f700e775c4b363
1.5.0-nullsafety2020-07-29T16:18:06.891594ZDownload65ef1d9224c022195ad83a98efde550b69e05d06e56fc54de6dd2e0e036bc252
1.5.0-nullsafety.12020-09-22T16:07:58.096906ZDownloade35c2532d0edab6a15d679c7d9030e778c46718f9369ccaf2611dc245cf4c6eb
1.5.0-nullsafety.22020-10-23T21:38:57.276035ZDownload0477cb492ce9fcdf2508e08151415b6aa69fcf55d7284e6131da87b8d66ba31e
1.5.0-nullsafety.32020-11-03T22:24:40.030699ZDownload01c8b54816c8c18596239113d42bff2a7bb348451de521a6814f73aca9441dfe
1.5.02021-02-03T01:26:47.292316ZDownload05955e3de2683e1746222efd14b775df7131139e07695dc8e24650f6b4204504
1.5.12022-06-15T20:48:50.737669ZDownload20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a
1.5.22025-09-17T14:59:47.902442ZDownload978783255c543aa3586a1b3c21f6e9d720eb315376a915872c61ef8b5c20177d
1.5.32026-08-28T20:42:37.375742ZDownload4177f68c237ea2128d1bee66ac17b2ce05ba3dbaafcbdd54c5d40a39d0b6b11c

Dependencies

async "^2.5.0"

stack_trace "^1.10.0"