puddle

Types

pub opaque type BookkeepingMessage(resource_type, result_type)
pub opaque type UsageMessage(resource_type, result_type)

Functions

pub fn apply(manager: Subject(BookkeepingMessage(a, b)), fun: fn(
    a,
  ) -> b, timeout: Int, rest: fn(Result(b, Nil)) ->
    Result(c, Nil)) -> Result(c, Nil)

checks-out a resource, applies the function and then checks-in the resource

Example

>  let assert Ok(manager) =
>    puddle.start(
>      4,
>      fn() {
>        Ok(int.random(1024, 8192))
>      },
>    )
>
>  fn fun(n) {
>    n * 2
>  }
>
>  let t1 =
>    task.async(fn() {
>      use r <- puddle.apply(manager, fun, 32)
>      r
>   })

>  let t2 = 
>    task.async(fn() {
>      use r <- puddle.apply(manager, fun, 32)
>      r
>    })

>  task.await(t1, 32)
>  task.await(t2, 32)
pub fn start(size: Int, new_resource: fn() -> Result(a, Nil)) -> Result(
  Subject(BookkeepingMessage(a, b)),
  StartError,
)
Search Document