commonMain.com.dokar.quickjs.util.Mutex.ext.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quickjs-kt Show documentation
Show all versions of quickjs-kt Show documentation
A QuickJS binding for idiomatic Kotlin, with Async/DSL/ES Modules support.
The newest version!
package com.dokar.quickjs.util
import kotlinx.coroutines.sync.Mutex
internal inline fun Mutex.withLockSync(
block: () -> T,
): T {
try {
while (!this.tryLock()) {
// Loop until the lock is available
}
return block()
} finally {
this.unlock()
}
}