3.5.102 • Published 10 months ago

@taktikorg/vel-deleniti v3.5.102

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

SubProcess Robot

Create subprocesses and deal with messaging. Good for delegating tasks to a differnet process

Import a function and run it using a child process

Before:

import { slowSynchronousTask } from "./synchronous-tasks";

export function synchronousTask(options) {
  return slowSynchronousTask(options);
}

After:

import { spawnProcess } from "subprocess-robot";

export async function asynchronousTask(options) {
  const { slowSynchronousTask } = await spawnProcess.import(
    require.resolve("./synchronous-tasks")
  );

  return await slowSynchronousTask(options);
}

Load balance your task between a pool of processes

Before:

import { slowSynchronousTask } from "./synchronous-tasks";

export function synchronousTask(options) {
  return slowSynchronousTask(options);
}

After:

import { spawnProcessPool } from "subprocess-robot";

export async function asynchronousTask(options) {
  const { slowSynchronousTask } = await spawnProcessPool.import(
    require.resolve("./synchronous-tasks")
  );

  return await slowSynchronousTask(options);
}

Manually create a subprocess and send messages between

Parent process:

import { spawnProcess } from 'subprocess-robot';

const childProcess = spawnProcess({
    script: require.resolve('./child')
});

childProcess.on('getUser', ({ id ) => {
    return {
        id,
        name: 'Daniel',
        logout() {
            // log the user out
        }
    }
});

Child process:

import { attachProcess } from "subprocess-robot";

const parentProcess = attachProcess();

let user = await parentProcess.send("getUser", { id: 1337 });

console.log(`Logging ${user.name} out`);
await user.logout();

Create a pool of processes and delegate tasks

Parent process:

import { spawnProcessPool } from "subprocess-robot";

const childProcessPool = spawnProcessPool({
  script: require.resolve("./child"),
});

let result = childProcessPool.send("do_some_blocking_task", data);

Child process:

import { attachProcess } from "subprocess-robot";

const parentProcess = attachProcess();

parentProcess.on("do_some_blocking_task", (data) => {
  return slowSynchronousCompile(data);
});

Manually create a pool of processes and import a function

Parent process:

import { spawnProcessPool } from "subprocess-robot";

const childProcessPool = spawnProcessPool();

let { doSomeBlockingTask } = await childProcessPool.import(
  require.resolve("./blockingTask")
);

let result = await doSomeBlockingTask(config);

Child process:

export function doSomeBlockingTask(config) {
  return slowSynchronousCompile(config);
}

Quick Start

npm install --save subprocess-robot

Tests

  • Run the tests:

    npm test
3.5.102

10 months ago

3.5.101

10 months ago

3.4.101

10 months ago

3.4.100

10 months ago

3.4.99

10 months ago

3.4.98

11 months ago

3.4.97

11 months ago

3.4.96

11 months ago

3.4.95

11 months ago

3.4.94

11 months ago

3.4.93

11 months ago

3.4.92

11 months ago

3.4.91

11 months ago

3.4.90

11 months ago

3.4.89

11 months ago

3.4.88

11 months ago

3.4.87

11 months ago

3.4.86

11 months ago

3.4.85

11 months ago

3.4.84

11 months ago

3.4.83

11 months ago

3.4.82

11 months ago

3.4.81

11 months ago

3.4.80

11 months ago

3.4.79

11 months ago

3.4.78

11 months ago

3.4.77

11 months ago

3.4.76

11 months ago

3.4.75

11 months ago

3.4.74

11 months ago

3.4.73

11 months ago

3.4.72

11 months ago

3.4.71

11 months ago

3.4.70

11 months ago

3.4.69

11 months ago

3.4.68

12 months ago

3.4.67

12 months ago

3.4.66

12 months ago

3.4.65

12 months ago

3.4.64

12 months ago

3.4.63

12 months ago

3.4.62

12 months ago

3.4.61

12 months ago

3.4.60

12 months ago

3.4.59

12 months ago

3.4.58

12 months ago

3.4.57

12 months ago

3.3.57

12 months ago

3.3.56

12 months ago

3.3.55

12 months ago

3.3.54

12 months ago

3.3.53

12 months ago

3.3.52

12 months ago

3.3.51

12 months ago

3.3.50

12 months ago

3.3.49

1 year ago

3.3.48

1 year ago

3.3.47

1 year ago

3.3.46

1 year ago

3.3.45

1 year ago

3.3.44

1 year ago

3.2.44

1 year ago

3.2.43

1 year ago

2.2.43

1 year ago

2.2.42

1 year ago

2.2.41

1 year ago

2.2.40

1 year ago

2.2.39

1 year ago

2.2.38

1 year ago

2.1.38

1 year ago

2.1.37

1 year ago

2.1.36

1 year ago

2.1.35

1 year ago

2.1.34

1 year ago

2.1.33

1 year ago

2.1.32

1 year ago

2.1.31

1 year ago

2.1.30

1 year ago

2.1.29

1 year ago

2.1.28

1 year ago

2.1.27

1 year ago

2.1.26

1 year ago

2.1.25

1 year ago

2.1.24

1 year ago

2.1.23

1 year ago

2.1.22

1 year ago

2.1.21

1 year ago

2.1.20

1 year ago

2.1.19

1 year ago

2.1.18

1 year ago

2.1.17

1 year ago

2.1.16

1 year ago

2.1.15

1 year ago

2.1.14

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

1 year ago

2.1.10

1 year ago

2.1.9

1 year ago

2.1.8

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago