tryAcquireNanos

suspend fun tryAcquireNanos(arg: Int, nanosTimeout: Long): Boolean

Attempts to acquire in exclusive mode, aborting if interrupted, and failing if the given timeout elapses. Implemented by first checking interrupt status, then invoking at least once .tryAcquire, returning on success. Otherwise, the thread is queued, possibly repeatedly blocking and unblocking, invoking .tryAcquire until success or the thread is interrupted or the timeout elapses. This method can be used to implement method Lock.tryLock.

Return

true if acquired; false if timed out

Parameters

arg

the acquire argument. This value is conveyed to .tryAcquire but is otherwise uninterpreted and can represent anything you like.

nanosTimeout

the maximum number of nanoseconds to wait

Throws

if the current thread is interrupted