Kombu.Resource (Kombu v0.1.0)

Copy Markdown View Source

Generic LIFO resource pool (kombu.resource.Resource).

Summary

Functions

Acquires a resource from pool (Resource.acquire).

Returns a specification to start this module under a supervisor.

Closes and removes all resources in the pool, including those currently in use (Resource.force_close_all).

Returns the current pool limit.

Creates a new %Kombu.Resource{} pool process.

Releases resource back to pool (Resource.release).

Discards a defective resource from pool and closes it (Resource.replace).

Resizes the pool limit (Resource.resize).

Pre-populates the pool with lazy resource factories up to limit - dirty.

Acquires a resource, passes it to fun.(resource), and ensures it is released afterwards.

Types

t()

@type t() :: %Kombu.Resource{
  close_fun: term(),
  collect_fun: term(),
  limit_exception: term(),
  new_fun: term(),
  pid: term(),
  prepare_fun: term(),
  release_fun: term()
}

Functions

acquire(pool, opts \\ [])

@spec acquire(t(), keyword()) :: term()

Acquires a resource from pool (Resource.acquire).

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

force_close_all(pool, opts \\ [])

@spec force_close_all(t(), keyword()) :: :ok

Closes and removes all resources in the pool, including those currently in use (Resource.force_close_all).

limit(resource)

@spec limit(t()) :: non_neg_integer() | nil

Returns the current pool limit.

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a new %Kombu.Resource{} pool process.

release(pool, resource)

@spec release(t(), term()) :: :ok

Releases resource back to pool (Resource.release).

replace(pool, resource)

@spec replace(t(), term()) :: :ok

Discards a defective resource from pool and closes it (Resource.replace).

resize(pool, new_limit, opts \\ [])

@spec resize(t(), non_neg_integer() | nil, keyword()) :: :ok

Resizes the pool limit (Resource.resize).

setup(resource)

@spec setup(t()) :: :ok

Pre-populates the pool with lazy resource factories up to limit - dirty.

validate_limit!(limit)

with_resource(pool, opts \\ [], fun)

@spec with_resource(t(), keyword(), (term() -> result)) :: result when result: var

Acquires a resource, passes it to fun.(resource), and ensures it is released afterwards.