thin wrapper around fcntl(F_SETLK)
A trivial wrapper around
F_SETLKW). Presently allows
a synchronous or asynchronous call to get a whole-file, exclusive, advisory
write lock on a file, or to block until one is possible.
This module has been crafted specifically to work on SmartOS, and may not work anywhere else. Please see fcntl(2) for more details on the locking semantics. In general, the lock will be released when either the file descriptor is closed, or the process exits. The manual page contains information on exceptions to this behaviour.
Will attempt to lock the open file descriptor
fd as described above. Once
the lock is acquired, or an error condition manifests,
callback(err) will be
Synchronous version of
var mod_fs = require'fs';var mod_lockfd = require'lockfd';var fd = mod_fsopenSync'/tmp/.lockfile' 'r+';console.error'open fd %d' fd;console.error'locking file...';mod_lockfdlockfdSyncfd;console.log'locked.';/** Do work...*/mod_fscloseSyncfd;processexit0;