acquire

suspend fun acquire()

Takes a permit: at once when one is free, else after waiting in the queue at most maxWait, or fails with QueryBusyException. The semaphore hands a released permit to the longest waiter (FIFO) and gives it back when that waiter was cancelled before it ran, a wait that ran out included. A permit the waiter has already received when its wait runs out is kept; one it has received when its caller is cancelled is given back, with release, before the cancellation goes on. Each permit taken is given back with one release: a caller that reads in chunks may give it back between two and take it again, so a lowered limit applies to it from its next chunk.