app-mutex
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

app-mutex.ts

Build Status
Application Mutex locker implementation for TypeScript 🐢

Install

yarn add app-mutex

Usage

import { Mutex } from "app-mutext";
 
new Mutex("4cdb4d66-2d29-47fd-adaa-b2e8e72a6803", (status) => {
    switch (status) {
        case "CLEAR": break; // its ok
        case "PID_DEAD": // warning
            console.log("last time app ran, a critical error occurred.")
            break;
        case "CONFLICT":
            console.log("[ERR] app already running.");
            process.exit(-1);
            break;
    }
});
 
 
/* ... */
 
your code...
 

Then run your code in two instances, start only one. 😱

Posible status of mutex

/**
 * Mutext status type
 * @argument ERR_NOT_INIT - Mutex not been initiated
 * @argument CLEAR        - Mutex status - success, you can run application
 * @argument CONFLICT     - Mutex detected runned this application
 * @argument PID_DEAD     - Mutex was noticed that the application died
 */

Why use it

  1. When you need to protect your system from running two or more instances of your program
  2. When to know if your instance is running 😏

License

MIT

Package Sidebar

Install

npm i app-mutex

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

12.7 kB

Total Files

16

Last publish

Collaborators

  • rijndael