bath
Types
An error returned when failing to apply a function to a pooled resource.
pub type ApplyError {
NoResourcesAvailable
CheckoutTimeout
}
Constructors
-
NoResourcesAvailable
There are no resources available in the pool.
-
CheckoutTimeout
The checkout timeout expired.
An error returned when creating a Pool
.
pub type InitError(resource_create_error) {
StartError(actor.StartError)
ResourceCreateError(resource_create_error)
}
Constructors
-
StartError(actor.StartError)
The actor failed to start.
-
ResourceCreateError(resource_create_error)
The resource creation function failed.
An error returned when the resource pool fails to shut down.
pub type ShutdownError {
ResourcesInUse
ShutdownTimeout
CalleeDown(reason: dynamic.Dynamic)
}
Constructors
-
ResourcesInUse
There are still resources checked out. Ignore this failure case by calling
force_shutdown
function. -
ShutdownTimeout
The shutdown timeout expired.
-
CalleeDown(reason: dynamic.Dynamic)
The pool was already down or failed to send the response message.
Functions
pub fn apply(
pool: Pool(a),
timeout: Int,
next: fn(a) -> b,
) -> Result(b, ApplyError)
Check out a resource from the pool, apply the next
function, then check
the resource back in.
let assert Ok(pool) = bath.init(10, fn() { Ok("Some pooled resource") })
use resource <- bath.apply(pool, 1000)
// Do stuff with resource...
pub fn force_shutdown(
pool: Pool(a),
resource_shutdown_function: fn(a) -> Nil,
) -> Nil
Shut down the pool, calling the resource_shutdown_function
on each
resource in the pool.
Will not fail, even if resources are checked out, and will call the
resource_shutdown_function
on both checked in and checked out resources.
pub fn init(
size: Int,
resource_create_function: fn() -> Result(a, b),
) -> Result(Pool(a), InitError(b))
Start a new resource pool.
// Creates a pool with 10 strings.
let assert Ok(pool) = bath.init(10, fn() { Ok("Some pooled resource") })