Skip to content

Latest commit

 

History

History
30 lines (18 loc) · 933 Bytes

README.md

File metadata and controls

30 lines (18 loc) · 933 Bytes

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

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