1.0.0 • Published 5 years ago
ontime-pm v1.0.0
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();
- processId - process ID
- processId - process ID
- V generic of variables
Others API depends on the implementation
1.0.0
5 years ago