package eio
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=c1f04986b401094176494863dde1ca9b292b59fdc679a9d7023e558d80fb5b15
sha512=92ed8cf20300b8a4e0141bdbc373c0803c5a24530cb65852637d905fff4a5b956a8859a00a424034ff78c1112da9b0391194bcd558326168bdebd1ce683a8890
doc/eio/Eio/Pool/index.html
Module Eio.PoolSource
A pool of resources.
This is useful to manage a collection of resources where creating new ones is expensive and so you want to reuse them where possible.
Example:
let buffer_pool = Eio.Pool.create 10 (fun () -> Bytes.create 1024) in
Eio.Pool.use buffer_pool (fun buf -> ...)Note: If you just need to limit how many resources are in use, it is simpler to use Eio.Semaphore instead.
create n alloc is a fresh pool which allows up to n resources to be live at a time. It uses alloc to create new resources as needed. If alloc raises an exception then that use fails, but future calls to use will retry.
The alloc function is called in the context of the fiber trying to use the pool.
You should take care about handling cancellation in alloc, since resources are typically attached to a switch with the lifetime of the pool, meaning that if alloc fails then they won't be freed automatically until the pool itself is finished.