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_secondsisNoneorSome(0), returns immediately withAppError::AllSlotsFull { max, waited_secs: 0 }. - If
wait_secondsisSome(n) > 0, enters a polling loop everycrate::constants::CLI_LOCK_POLL_INTERVAL_MSms until the deadline expires, returningAppError::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.