The library is used to manage and control some processes which you are able to run in the browser or NodeJS. There is sometimes need to split a complicated process into small pieces of code. It means that you can create simple tasks and combine them into the one process.
Process manager - allows you to controll your processes.
Process - allows you to controll tasks.
Task - simple iteration.
yarn add ontime-pm
// or
npm install ontime-pm
// index.ts
import { ProcessManager, Process, Task } from 'ontime-pm';
// Create instance of process manager
const processManager: ProcessManager = new ProcessManager('user');
// Create Tasks classes
class Task1 extends Task {
async run() {
console.log('Task 1. Do something...');
}
async pause() {}
async resume() {}
async cancel() {}
}
class Task2 extends Task {
async run() {
console.log('Task 2. Do something...');
}
async pause() {}
async resume() {}
async cancel() {}
}
class Task3 extends Task {
async run() {
console.log('Task 3. Do something...');
}
async pause() {}
async resume() {}
async cancel() {}
}
// Create Custom Process class
class CustomProcess extends Process<{}, []> {
public get name(): string { return 'test'; }
public get tasks(): any[] { return [Task1, Task2, Task3]; }
}
// Register custom process inside process manager
pm.register('test', CustomProcess);
// Create a new instance of custom process
const proc: CustomProcess = await pm.create('test');
// subscribe on all events
proc.on('*', (...args: any[]) => console.log(...args));
// run custom process
proc.run();
- - userId - Optional. User ID.
- The method registers a class process in the system - processName - process name - procClass - process class
-
The method creates new process instance.
The method returns new instance.
- processName - process name - options - process variables - restoreId. Optional. Using for restore process context.
-
The method returns a status of an instance of a process
- processId - process ID
-
The method returns an instance of Process by a process ID
- processId - process ID
- The method returns a list of active processes
- V generic of variables
- Process ID
- Process name. Getter property.
- Process tasks. Getter property.
- - userId - Optional. User ID. - vars - Optional. Process variables. - restoreId - Optional. Using for restore process context.
- The method runs the process to execute
- The method cancels the process
- The method pauses the process
- The method resumes the process
- The method returns a status of the process
- The method returns process variables
- Destructor
- The method cancels the task
- The method pauses the task
- The method resumes the task
Others API depends on the implementation