Ex4pm.Runtime.PlanningPool (ex4pm v26.9.9)

Copy Markdown View Source

A thin, real wrapper around Reactor.Executor.ConcurrencyTracker that bounds concurrent planning work.

Reactor.Executor.ConcurrencyTracker is a GenServer already started by the vendored :reactor OTP application's supervision tree (deps/reactor/lib/reactor/application.ex), so this module does not start or own that process — it only allocates/uses pools against it.

A pool is identified by an opaque pool_key (a reference/0, per the real ConcurrencyTracker API). acquire/2 returns the number of slots actually granted (which may be less than requested, or zero, per the real ConcurrencyTracker.acquire/2 contract) rather than blocking.

Summary

Functions

Attempt to acquire how_many planning slots (default 1) from the pool.

Tear down the pool. Does not affect slots already acquired by users.

Allocate a new bounded planning pool with limit concurrent slots.

Release how_many (default 1) previously acquired slots back to the pool.

Release all acquired slots for the calling process automatically when it exits.

Return {:ok, available, limit} for the pool, or {:error, reason}.

Types

pool_key()

Functions

acquire(pool_key, how_many \\ 1)

@spec acquire(pool_key(), pos_integer()) :: {:ok, non_neg_integer()}

Attempt to acquire how_many planning slots (default 1) from the pool.

Returns {:ok, n} where n is the number of slots actually granted; n may be less than how_many, including 0, if the pool is exhausted. The caller must only proceed with the work it was actually granted slots for.

destroy(pool_key)

@spec destroy(pool_key()) :: :ok

Tear down the pool. Does not affect slots already acquired by users.

new(limit)

@spec new(pos_integer()) :: pool_key()

Allocate a new bounded planning pool with limit concurrent slots.

release(pool_key, how_many \\ 1)

@spec release(pool_key(), pos_integer()) :: :ok | :error

Release how_many (default 1) previously acquired slots back to the pool.

release_on_exit(pool_key, pid \\ self())

@spec release_on_exit(pool_key(), pid()) :: :ok

Release all acquired slots for the calling process automatically when it exits.

status(pool_key)

@spec status(pool_key()) :: {:ok, non_neg_integer(), pos_integer()} | {:error, any()}

Return {:ok, available, limit} for the pool, or {:error, reason}.