3.5.102 • Published 1 year ago

@taktikorg/vel-deleniti v3.5.102

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year 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

1 year ago

3.5.101

1 year ago

3.4.101

1 year ago

3.4.100

1 year ago

3.4.99

1 year ago

3.4.98

1 year ago

3.4.97

1 year ago

3.4.96

1 year ago

3.4.95

1 year ago

3.4.94

1 year ago

3.4.93

1 year ago

3.4.92

1 year ago

3.4.91

1 year ago

3.4.90

1 year ago

3.4.89

1 year ago

3.4.88

1 year ago

3.4.87

1 year ago

3.4.86

1 year ago

3.4.85

1 year ago

3.4.84

1 year ago

3.4.83

1 year ago

3.4.82

1 year ago

3.4.81

1 year ago

3.4.80

1 year ago

3.4.79

1 year ago

3.4.78

1 year ago

3.4.77

1 year ago

3.4.76

1 year ago

3.4.75

1 year ago

3.4.74

1 year ago

3.4.73

1 year ago

3.4.72

1 year ago

3.4.71

1 year ago

3.4.70

1 year ago

3.4.69

1 year ago

3.4.68

1 year ago

3.4.67

1 year ago

3.4.66

1 year ago

3.4.65

1 year ago

3.4.64

1 year ago

3.4.63

1 year ago

3.4.62

1 year ago

3.4.61

1 year ago

3.4.60

1 year ago

3.4.59

1 year ago

3.4.58

1 year ago

3.4.57

1 year ago

3.3.57

1 year ago

3.3.56

1 year ago

3.3.55

1 year ago

3.3.54

1 year ago

3.3.53

1 year ago

3.3.52

1 year ago

3.3.51

1 year ago

3.3.50

1 year 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