Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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")