池
一個用於管理有限資源池的類。
- 星標
- 50
- 分支
- 15
- 最近推送(UTC)
- 2024年12月11日
- 專案狀態
- 已封存
原始 README
以下為英文專案原文快照,最新內容請造訪 GitHub。
[!IMPORTANT]
This repo has moved to https://github.com/dart-lang/tools/tree/main/pkgs/pool
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;
});
}
}
使用的依賴
依賴清單 5 項
- async
^2.5.0 - stack_trace
^1.10.0 - dart_flutter_team_lints開發依賴
^3.0.0 - fake_async開發依賴
^1.2.0 - test開發依賴
^1.16.6
如何選擇適合專案的儲存庫?
先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。
- 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
- 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
- 使用前在 GitHub 確認 README、授權條款與 Issues。
來源與維護
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗