lock: Create or Unlock a Lock

Description Usage Arguments Value Examples

Description

A wrapper for 'synchronicity' package, but user can interrupt the lock procedure anytime, and don't have to worry about whether the lock exists or not.

Usage

1
2
3
dipsaus_lock(name, exclusive = TRUE, timeout = 10)

dipsaus_unlock(name, exclusive = TRUE, timeout = 10)

Arguments

name

character, the locker's name, must be only letters and digits

exclusive

logical whether the locker is exclusive. True for write access, False for read access. Default is true.

timeout

numeric, seconds to wait for the locker to lock or unlock

Value

Logical, whether the operation succeed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# unlock to prepare for the example
dipsaus_unlock('testlocker', timeout = 0.01)

# Create a locker, return TRUE
lock_success = dipsaus_lock('testlocker')
if(lock_success){
  cat2('testlocker has been locked')
}

# test whether locker has been locked
lock_success = dipsaus_lock('testlocker', timeout = 0.01)
if(!lock_success){
  cat2('attempt to lock testlocker failed')
}

# unlock
dipsaus_unlock('testlocker', timeout = 0.01)

dipsaus documentation built on Sept. 6, 2021, 5:08 p.m.