os.filelock
fn new #
fn new(file_name string) FileLock
new creates a sidecar lock file that is removed again when the lock is released.
fn new_file #
fn new_file(path string, options LockOptions) FileLock
new_file creates a lock for an existing file path using OS-level file locking.
fn LockMode.from #
fn LockMode.from[W](input W) !LockMode
fn LockTarget.from #
fn LockTarget.from[W](input W) !LockTarget
enum LockMode #
enum LockMode {
shared
exclusive
}
LockMode describes whether an existing file lock is shared/read or exclusive/write.
struct FileLock #
struct FileLock {
name string
mode LockMode = .exclusive
start u64
len u64
target LockTarget = .sidecar
mut:
fd i64
}
fn (FileLock) acquire #
fn (mut l FileLock) acquire() !
acquire blocks until the lock is acquired.
fn (FileLock) release #
fn (mut l FileLock) release() bool
release unlocks the file and closes the underlying file descriptor or handle.
fn (FileLock) try_acquire #
fn (mut l FileLock) try_acquire() bool
try_acquire tries to acquire the lock without blocking.
fn (FileLock) wait_acquire #
fn (mut l FileLock) wait_acquire(timeout time.Duration) bool
wait_acquire keeps trying to acquire the lock until timeout expires.
struct LockOptions #
@[params]
struct LockOptions {
pub:
mode LockMode = .exclusive
start u64
len u64
}
LockOptions configures how new_file locks an existing file.