Rel_pool
Pools of reusable resources.
This can be used for pooling database connections in multithreaded programs.
The type for pools of reusable resources of type 'a
whose life-cycle management returns errors of type 'b
.
val create :
create:(unit -> ('a, 'b) Stdlib.result) ->
dispose:('a -> (unit, 'b) Stdlib.result) ->
int ->
('a, 'b) t
create ~create ~dispose limit
is a pool with at most limit
reusable ressources created with create
. dispose
is only called when dispose
is; in particular it is not called when the pool is garbage collected.
val with' : ('a, 'b) t -> ('a -> 'c) -> ('c, 'b) Stdlib.result
with' p f
blocks the calling thread until a resource r
can be reused or created in the limit given to create
. Returns Ok (f
r)
and releases the ressource r
back to the pool for reuse (even if f
raises). Error _
is returned in case the resource r
had to be created and it errored.
val try_with : ('a, 'b) t -> ('a -> 'c) -> ('c, 'b) Stdlib.result option
val dispose : ('a, 'b) t -> (unit, 'b list) Stdlib.result