🛁 Bath
Bath is a generic resource pool for Gleam. It can be used to manage a pool of any value, such as database connections, file handles, or other resources.
Installation
gleam add bath@1
Usage
import bath
import fake_db
pub fn main() {
// Create a pool of 10 connections to some fictional database.
let assert Ok(pool) = bath.init(10, fn() { fake_db.connect() })
// Use the pool. Shown here in a block to use `use`.
let assert Ok("Hello!") = {
use conn <- bath.apply(pool, 1000)
// Do stuff with the connection...
"Hello!"
}
// Close the pool.
let assert Ok(_) = bath.shutdown(pool, fn(conn) { fake_db.close(conn) }, 1000)
}
Further documentation can be found at https://hexdocs.pm/bath.
Development
gleam run # Run the project
gleam test # Run the tests