Socket
Socket
Sign inDemoInstall

cross-process-lock

Package Overview
Dependencies
3
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cross-process-lock

Cross-process file locking solution with lock-queue


Version published
Weekly downloads
5.9K
decreased by-3.07%
Maintainers
1
Install size
151 kB
Created
Weekly downloads
 

Readme

Source

cross-process-lock

Downloads Version@npm Version@git CI Docs

Cross-process file locking solution with lock-queue

Usage

const { lock } = require('cross-process-lock');
const { writeFileSync } = require('fs');
// create a lock for the given file
const unlock = await lock('file.txt')
// do smth with the file here
writeFileSync('file.txt', 'some content', 'utf8');
// unlock file with the received function
return unlock();

API

Lock

lock(file[, options]) - creates a lock for the given file for the actual process

Arguments:

  • {string} file - the path of the file needs to be locked
  • {lockOptions} options - the options to use to lock file, e.g timeouts

Returns: Promise<Function> - resolved with unlock function in case of successful lock; rejected in case of file couldn't be lock in the given timeout

Unlock

unlock(file) - deletes the lock for the given file for the actual process

Arguments:

  • {string} file - the path of the file needs to be unlocked

Returns: Promise - resolved in case of successful unlock or rejected in case of any error

WithLock

withLock(file[, options], callback) - executes the callback with locking before and unlocking after the execution

Arguments:

  • {string} file - path of the file needs to be locked
  • {lockOptions} options - the options to use to lock file, e.g timeouts
  • {() => Promise<T>} callback - the function to be executed

Returns: Promise<T> - resolved/rejected with the result of the callback

lockOptions

OptionDescriptionDefault
lockTimeout {number}timeout (ms) when locks automatically released20 minutes
waitTimeout {number}timeout (ms) until lock waits to lock a file10 seconds

Debug

The package uses the debug NPM package with cross-process-lock:PID name, where PID is the process ID of the current process.

To enable debug logging, use for example the DEBUG=cross-process-lock:* environment variable, but for more information, check the documentation of the debug package.

Keywords

FAQs

Last updated on 27 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc