ORESoftware/live-mutex

Mutex betwen processes

Closed this issue · 3 comments

Can this be used as a mutex between two processes which would want to require access to let's say resource X? I can implement what I need with lockfile but I'm also interested to see whether I can find a working solution with your live-mutex implementation

From your readme "Live-Mutex is a non-distributed mutex for synchronization across multiple processes/threads"

Can you provide an example for that?

yeah of course, this is what live-mutex is for. what you want to do is launch a broker. then in the two node.js processes you will make a connection to the broker with the client api. so with bash that looks like this:

#!/usr/bin/env bash

lmx start &
node first.js &
node second.js &

in first.js / second.js, you will connect to the broker like so:

import {Client} from 'live-mutex';
const c = new Client();
c.ensure().then(() => {
   // do your locking/unlocking according to the instructions in readme
});

the above uses TCP, if you want something faster (if everything is on one machine), then you can use Unix Domain Sockets. Let me know if you get it working with TCP and I can demo later how to use UDS.

If you don't pass a port, it defaults to 6970, the broker and clients both default to that port.

Thanks, I'll give it a try!

any luck with it? LMK I will close this issue o/w. You can see the docs folder for some examples.

here is a simple example: https://github.com/ORESoftware/live-mutex/blob/master/docs/examples/simple.md