Skip to main content

acquire_cli_slot

Function acquire_cli_slot 

Source
pub fn acquire_cli_slot(
    max_concurrency: usize,
    wait_seconds: Option<u64>,
) -> Result<(File, usize), AppError>
Expand description

Acquires a concurrency slot from the max_concurrency-position semaphore.

Iterates slots 1..=max_concurrency attempting try_lock_exclusive on each cli-slot-N.lock file. When a free slot is found, returns (File, slot_number). If all slots are occupied:

  • If wait_seconds is None or Some(0), returns immediately with AppError::AllSlotsFull { max, waited_secs: 0 }.
  • If wait_seconds is Some(n) > 0, enters a polling loop every crate::constants::CLI_LOCK_POLL_INTERVAL_MS ms until the deadline expires, returning AppError::AllSlotsFull { max, waited_secs: n } if no slot opens.

The returned File MUST be kept alive until the process exits; dropping it releases the slot automatically via the implicit flock on close.