This package has been deprecated

Author message:

This package is replace by [manager-process](https://www.npmjs.com/package/manager-process)

first-officer
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

First Officer

In multi-processing scenario, it's better to handle some operations in just one process, rather than repeatedly running them in all processes. If you you have all control of the master process, you can just put the code in the master process. However, you don't have control, e.g. using PM2, you need a way to find out which process should run the specific program. Such a process, I call it the First Officer process.

The module provides two functions, one gets the pid of the first officer process, one checking whether the current process is the first officer process.

Example

const FirstOfficer = require("first-officer");

(async () => {
    let pid = await FirstOfficer.getPid();
    let isFirstOfficer = await FirstOfficer.isFirstOfficer();
    let members = await FirstOfficer.getCrew();

    if (isFirstOfficer) {
        // TODO...
    }

    // This is the same
    if (pid === process.pid) {
        // TODO...
    }

    console.log(members);
    // Array<{
    //  pid: number,
    //  ppid?: number,
    //  uid?: number;
    //  gid?: number;
    //  name: string;
    //  cmd: string;
    // }>
})();

Package Sidebar

Install

npm i first-officer

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

5.3 kB

Total Files

6

Last publish

Collaborators

  • ayonli