LemonGateway.EngineLock (lemon_gateway v0.1.0)

View Source

Mutex lock preventing concurrent engine runs on the same session.

Provides fair FIFO queueing with configurable timeouts. Monitors lock holders and automatically releases locks when processes die. Periodically sweeps stale locks that exceed max_lock_age_ms.

Summary

Functions

Acquires the engine lock for the given thread key.

Returns a specification to start this module under a supervisor.

Types

thread_key()

@type thread_key() :: term()

Functions

acquire(thread_key, timeout_ms \\ 60000)

@spec acquire(thread_key(), non_neg_integer()) :: {:ok, (-> :ok)} | {:error, :timeout}

Acquires the engine lock for the given thread key.

Returns {:ok, release_fn} where release_fn is a zero-arity function that must be called to release the lock. Returns {:error, :timeout} if the lock cannot be acquired within timeout_ms.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)