tryUse

fun tryUse(key: K, cooldownMillis: Long, onExpiry: () -> Unit = {}): Boolean

Tries to use the specified key with the given cooldownMillis.

If the key is ready, sets the cooldown and returns true. Otherwise, returns false.

Return

true if the key was ready and the cooldown was set, false otherwise

Parameters

key

the key to try to use

cooldownMillis

the duration of the cooldown in milliseconds to set if ready

onExpiry

optional callback to execute when the cooldown expires


fun tryUse(key: K, cooldown: Duration, onExpiry: () -> Unit = {}): Boolean

Tries to use the specified key with the given cooldown.

If the key is ready, sets the cooldown and returns true. Otherwise, returns false.

Return

true if the key was ready and the cooldown was set, false otherwise

Parameters

key

the key to try to use

cooldown

the Duration of the cooldown to set if ready

onExpiry

optional callback to execute when the cooldown expires