distribute/connection_pool
Types
Result of batch operations with error aggregation
pub type BatchResult(e) {
BatchResult(
total: Int,
successful: Int,
failed: Int,
errors: List(e),
)
}
Constructors
-
BatchResult( total: Int, successful: Int, failed: Int, errors: List(e), )
Connection handle from a pool
pub type Connection
Pool operation errors
pub type PoolError {
PoolExhausted
ConnectionFailed(String)
InvalidConfig(String)
InvalidPool
}
Constructors
-
PoolExhaustedPool has reached maximum connections
-
ConnectionFailed(String)Connection establishment failed
-
InvalidConfig(String)Invalid pool configuration
-
InvalidPoolPool was destroyed or invalid
Values
pub fn new(
target_node: String,
max_connections: Int,
) -> Result(Pool, PoolError)
Create a new connection pool backed by ETS for atomic operations
pub fn send_batch(
pool: Pool,
messages: List(#(String, a)),
send_fn: fn(String, a) -> Result(Nil, b),
) -> Result(List(Result(Nil, b)), PoolError)
Send multiple messages in a batch using a single connection
pub fn send_batch_parallel(
pool: Pool,
messages: List(#(String, a)),
send_fn: fn(String, a) -> Result(Nil, b),
) -> Result(BatchResult(b), PoolError)
Send multiple messages in parallel (up to pool size) with error aggregation
pub fn stress_test(
pool: Pool,
ops_per_worker: Int,
workers: Int,
) -> Result(PoolStats, PoolError)
Run a concurrency stress-test against a pool. This spawns multiple worker processes
each performing ops get/release cycles using the pool; returns final pool stats.
pub fn with_connection(
pool: Pool,
f: fn(Connection) -> a,
) -> Result(a, PoolError)
Execute a function with a pooled connection (automatically released)