pub repository
mirror.p-hatan.irpool
1.3.0A class for managing a finite pool of resources.
Readme
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(() => return 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.3.0
- Add a
Pool.donegetter that returns the same future returned byPool.close().
1.2.4
- Fix a strong-mode error.
1.2.3
- Fix a bug in which
Pool.withResource()could throw aStateErrorwhen 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
TimeoutExceptionis now correctly thrown if the pool detects a deadlock.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add poolpubspec.yaml
name: pool
version: 1.3.0
author: Dart Team <misc@dartlang.org>
description: A class for managing a finite pool of resources.
homepage: https://github.com/dart-lang/pool
dependencies:
async: "^1.4.0"
stack_trace: ">=0.9.2 <2.0.0"
environment:
sdk: ">=1.9.0 <2.0.0"
dev_dependencies:
fake_async: ">=0.1.0 <0.2.0"
test: ">=0.12.0 <0.13.0"
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 1.0.0 | 2014-07-24T00:26:45.514990Z | Download | 465486caca9ed81e493e439e0647fcbcfd24596c64a4ca19c56029ea901e6617 |
| 1.0.1 | 2014-07-24T20:29:49.339400Z | Download | bddb6031a7107265e5fd5cf7cdfbd78a5549aa7733eddc60d8b20ffe177b00a8 |
| 1.0.2 | 2015-05-23T01:46:07.653Z | Download | 99c7862d0f132fcf6c4d8ca0df5e765644706d779a81bddee2b62a6c976cf267 |
| 1.1.0 | 2015-06-24T22:05:06.605Z | Download | 4b948db046cc34eb4a75b0a7ab68b126a166f349ee6a35d4f5209b097699f458 |
| 1.2.0 | 2015-10-09T00:46:54.027Z | Download | 8bd4bcd8e9be1d302852ecda589a86d4c9d0531165cdedc6707ac36864ec35ca |
| 1.2.1 | 2015-10-28T21:47:53.594Z | Download | 9031d5b75a72d3eef80d3193d39245076836d0ad6b9b8ef998f76a54825648b6 |
| 1.2.2 | 2016-03-31T23:48:56.060Z | Download | 48ae768fbf8dbaec84d741634eb529a07b391e74d7c66a12bd738eda881b0286 |
| 1.2.3 | 2016-04-04T22:44:26.904Z | Download | 264ec1d4a12bf0cca122ed58f0659666249390c1bd33bf30b1fa271225e0e4ad |
| 1.2.4 | 2016-05-03T23:28:03.549Z | Download | c48abab9c32a0e66293a608abaaacfa1149d304096c5a688fe81d6d7ab705c89 |
| 1.3.0 | 2017-02-16T21:10:59.980Z | Download | 71dbb9bdb3a0ea0b3ab19744cf267bd94e2f38c48ed2d287c78a593391480ddc |
| 1.3.1 | 2017-05-17T03:45:18.067062Z | Download | e716b5317ca6dcb9b6bf92d5c6fc941169860397aa8b61d6e2ef5855161e36d3 |
| 1.3.2 | 2017-09-21T15:52:39.565577Z | Download | baf19276e26032dca6eb40a6cb2db46bfe4ef3cc7cc71fb94cc8b66d7735e3fd |
| 1.3.3 | 2017-09-22T20:42:21.349569Z | Download | 53c4e0af70dc55cfd678c9003486de7f3e1f33635a0f86ecdfc638ee55e501fd |
| 1.3.4 | 2018-01-04T16:25:51.076720Z | Download | a6ffa8eeace0c176a21386d3fceb82261f695c29459e583014daf0fab57584b4 |
| 1.3.5 | 2018-05-18T22:34:29.099226Z | Download | 90f4769eeb9d983b0be9a764b877a70b00ab650c68aafa35c7866dd299d3fcfd |
| 1.3.6 | 2018-07-20T21:46:46.644806Z | Download | 4ac7f0582237de67b38e08a1e643c5da81b186504e391b8ff3772ad3b7bf312a |
| 1.4.0 | 2019-01-09T01:11:04.645539Z | Download | d5aa3ff42fe4f3a938c65f3c397895e5f888aea567ad7a5056f700e775c4b363 |
| 1.5.0-nullsafety | 2020-07-29T16:18:06.891594Z | Download | 65ef1d9224c022195ad83a98efde550b69e05d06e56fc54de6dd2e0e036bc252 |
| 1.5.0-nullsafety.1 | 2020-09-22T16:07:58.096906Z | Download | e35c2532d0edab6a15d679c7d9030e778c46718f9369ccaf2611dc245cf4c6eb |
| 1.5.0-nullsafety.2 | 2020-10-23T21:38:57.276035Z | Download | 0477cb492ce9fcdf2508e08151415b6aa69fcf55d7284e6131da87b8d66ba31e |
| 1.5.0-nullsafety.3 | 2020-11-03T22:24:40.030699Z | Download | 01c8b54816c8c18596239113d42bff2a7bb348451de521a6814f73aca9441dfe |
| 1.5.0 | 2021-02-03T01:26:47.292316Z | Download | 05955e3de2683e1746222efd14b775df7131139e07695dc8e24650f6b4204504 |
| 1.5.1 | 2022-06-15T20:48:50.737669Z | Download | 20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a |
| 1.5.2 | 2025-09-17T14:59:47.902442Z | Download | 978783255c543aa3586a1b3c21f6e9d720eb315376a915872c61ef8b5c20177d |
| 1.5.3 | 2026-08-28T20:42:37.375742Z | Download | 4177f68c237ea2128d1bee66ac17b2ce05ba3dbaafcbdd54c5d40a39d0b6b11c |
Dependencies
async "^1.4.0"
stack_trace "\u003e=0.9.2 \u003c2.0.0"