A lightweight wrapper around proper-lockfile
to simplify wrapping a user function inside a file lock.
Intended usage:
const Lock = require('runlocked').Lock
let lockfile = new Lock('./mylockdir', 'mylockname' )
function myfunc() {
return "Hi"
}
lockfile.runlocked( myfunc )
.then( console.log ) // Ouputs "Hi"
Expected behavior
runlocked
returns a promise.- If lock cannot be acquired ( disk error, or more likely, lock already held ) then user code will not be run.
The error internal to
runlocked
will be returned viaPromise.reject
. - If lock is acquired then user code will run.
runlocked
will return whatever the user code returns ( or throws )- If user code completes succesfully,
runlocked
returns the value returned by the user's code - If user code errors,
runlocked
will return a promise rejection with the error
- If user code completes succesfully,