Skip to content
/ tcp-mutex Public

very naive implementation of mutex nodejs applications over 'locking' a tcp port

Notifications You must be signed in to change notification settings

7c/tcp-mutex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

npm i --save https://github.com/7c/tcp-mutex 

Typescript

import { tryLock } from '@7c/tcp-mutex';

// somewhere in your main code entry
await tryLock(1337)

CommonJS

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

About

very naive implementation of mutex nodejs applications over 'locking' a tcp port

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published