withLock

fun <T> Semaphore.withLock(block: () -> T): T

Acquires a permit from this Semaphore, executes block, and releases the permit in a finally block.

Return

the result of block.

Parameters

block

the code to execute while holding the permit.

Type Parameters

T

the return type of block.