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
runlockedreturns 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
runlockedwill be returned viaPromise.reject. - If lock is acquired then user code will run.
runlockedwill return whatever the user code returns ( or throws )- If user code completes succesfully,
runlockedreturns the value returned by the user's code - If user code errors,
runlockedwill return a promise rejection with the error
- If user code completes succesfully,