pool
Uma classe para gerenciar um pool finito de recursos.
- Estrelas
- 50
- Forks
- 15
- Último push (UTC)
- 11 de dez. de 2024
- Status do projeto
- Arquivado
README original
Texto original em inglês. Visite o GitHub para a versão atual.
[!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;
});
}
}
Dependências usadas
Lista de dependências 5 itens
- async
^2.5.0 - stack_trace
^1.10.0 - dart_flutter_team_lintsDesenvolvimento
^3.0.0 - fake_asyncDesenvolvimento
^1.2.0 - testDesenvolvimento
^1.16.6
Como escolher um repositório para seu projeto?
Filtre pelo caso de uso, compare a atividade e confira o projeto original antes de adotá-lo.
- Busque por nome, autor ou descrição e filtre por tema.
- Compare estrelas, forks e envios recentes. Estrelas indicam interesse, mas não garantem qualidade.
- Confira o README, a licença e as issues no GitHub antes de usar o projeto.
Fontes e manutenção
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗
- dart-archive/pool · GitHub ↗
- GitHub Docs — Saving repositories with stars ↗
- Diretório mantido por Ducafecat ↗