Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/7c/tcp-mutex
very naive implementation of mutex nodejs applications over 'locking' a tcp port
https://github.com/7c/tcp-mutex
mutex-lock nodejs tcp
Last synced: about 1 month ago
JSON representation
very naive implementation of mutex nodejs applications over 'locking' a tcp port
- Host: GitHub
- URL: https://github.com/7c/tcp-mutex
- Owner: 7c
- Created: 2018-01-19T14:28:04.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-09-23T21:31:46.000Z (3 months ago)
- Last Synced: 2024-10-28T10:55:12.881Z (about 2 months ago)
- Topics: mutex-lock, nodejs, tcp
- Language: TypeScript
- Size: 81.1 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tcp-mutex
This small library is there to acquire a tcp based lock by opening a tcp-server. Since ports cannot be listened from more than 1 process we can use this behaviour to acquire a kind of lock based on tcp-port.## Installation
```bash
npm i --save https://github.com/7c/tcp-mutex
```## Typescript
```typescript
import { tryLock } from '@7c/tcp-mutex';// somewhere in your main code entry
await tryLock(1337)
```## CommonJS
```javascript
const { tryLock } = require('@7c/tcp-mutex');tryLock(1337).then(()=>{
console.log("locked successfully");
// we can start our application here
}).catch(err=>{
console.log("This application already started");
process.exit(0);
});
```## Demo
![Demonstration](https://github.com/7c/tcp-mutex/blob/master/tcpmutex.gif?raw=true "Demonstration")