scoop:scoop.platform:0.1.0
src/fs/file_lock.scoop
Selected production source · src/fs/file_lock.scoop
1
package scoop.platform.fs3
/** Borrows a non-nested file lock and releases it on every exit. */4
public fun <R> File.withLock(shared: Boolean = false, block: () -> R): R {5
val scope = FileLockScope(this)6
lock(shared)7
return scope.use { block() }8
}10
private class FileLockScope(private val file: File): Closeable {11
public override fun close() {12
file.unlock()13
}14
}