A flexible task management library supporting TypeScript, allowing for task buffering, scheduling, and execution with dependency management.
Go to file
2024-05-29 14:17:28 +02:00
.gitea/workflows fix(core): update 2023-10-20 13:05:39 +02:00
.vscode fix(core): update 2021-11-11 20:48:31 +01:00
test feat(Task): Tasks can now be blocked by other tasks. 2023-08-04 13:03:28 +02:00
ts fix(core): update 2023-10-20 13:05:39 +02:00
.gitignore fix(core): update 2020-07-12 00:48:51 +00:00
.npmignore update dependencies 2016-09-02 18:11:33 +02:00
LICENSE Initial commit 2016-02-07 22:11:30 +01:00
npmextra.json update tsconfig 2024-04-14 18:38:20 +02:00
package.json update description 2024-05-29 14:17:28 +02:00
pnpm-lock.yaml fix(core): update 2023-10-20 13:05:39 +02:00
readme.hints.md update tsconfig 2024-04-14 18:38:20 +02:00
readme.md update tsconfig 2024-04-14 18:38:20 +02:00
tsconfig.json fix(core): update 2023-10-20 13:05:39 +02:00

@push.rocks/taskbuffer

flexible task management. TypeScript ready!

Install

To install @push.rocks/taskbuffer, use the following npm command:

npm install @push.rocks/taskbuffer --save

This will add @push.rocks/taskbuffer to your project's dependencies, allowing you to use it within your TypeScript project.

Usage

@push.rocks/taskbuffer offers a versatile way to manage tasks in your application. Whether you need simple asynchronous task execution, buffered tasks to limit concurrent executions, or more complex scenarios involving task chaining and parallel execution, @push.rocks/taskbuffer has got you covered. Below, you'll find detailed examples showcasing the module's capabilities and how to use them in TypeScript.

Basic Task Execution

To create and run a simple task:

import { Task } from '@push.rocks/taskbuffer';

const simpleTask = new Task({
  name: 'SimpleTask',
  taskFunction: async () => {
    console.log('Executing a simple task');
    // Perform your task here (e.g., fetch data from an API)
  }
});

// Trigger the task
simpleTask.trigger();

This basic example creates a task that prints a message to the console when executed.

Buffered Task Execution

Buffered tasks allow you to throttle task executions, for example, to avoid overwhelming a server with simultaneous requests:

import { Task } from '@push.rocks/taskbuffer';

const bufferedTask = new Task({
  name: 'BufferedTask',
  taskFunction: async () => {
    // Task implementation
    console.log('Buffered task execution');
  },
  buffered: true,
  bufferMax: 3 // Maximum number of concurrent executions
});

// Trigger the task multiple times
bufferedTask.trigger();
bufferedTask.trigger();
bufferedTask.trigger();
bufferedTask.trigger();

In this scenario, only three instances of bufferedTask will run concurrently, thanks to the buffer settings.

Task Chains

Task chains are a powerful feature that allows you to execute tasks in a specified order:

import { Task, Taskchain } from '@push.rocks/taskbuffer';

const firstTask = new Task({
  name: 'FirstTask',
  taskFunction: async () => {
    console.log('First task execution');
    // First task logic
  }
});

const secondTask = new Task({
  name: 'SecondTask',
  taskFunction: async () => {
    console.log('Second task execution');
    // Second task logic
  }
});

const taskChain = new Taskchain({
  name: 'MyTaskChain',
  taskArray: [firstTask, secondTask] // Tasks will be executed in the order they are provided
});

// Trigger the task chain
taskChain.trigger();

Parallel Task Execution

To run tasks in parallel, use Taskparallel:

import { Task, Taskparallel } from '@push.rocks/taskbuffer';

const taskOne = new Task({
  name: 'TaskOne',
  taskFunction: async () => {
    // Task one logic
    console.log('Task one execution');
  }
});

const taskTwo = new Task({
  name: 'TaskTwo',
  taskFunction: async () => {
    // Task two logic
    console.log('Task two execution');
  }
});

const parallelTask = new Taskparallel({
  taskArray: [taskOne, taskTwo] // These tasks will be executed in parallel
});

// Trigger the parallel tasks
parallelTask.trigger();

Task Scheduling with Task Manager

@push.rocks/taskbuffer also provides a TaskManager to schedule tasks using cron expressions:

import { Task, TaskManager } from '@push.rocks/taskbuffer';

const scheduledTask = new Task({
  name: 'ScheduledTask',
  taskFunction: async () => {
    console.log('Scheduled task execution');
    // Task logic here
  }
});

const taskManager = new TaskManager();
taskManager.addAndScheduleTask(scheduledTask, '0 * * * * *'); // Execute task at the start of every minute

// Start the task manager to enable the scheduled execution
taskManager.start();

Advanced Use Cases

The flexibility of @push.rocks/taskbuffer allows for more sophisticated task management scenarios. You can combine the features mentioned above to fit your specific needs, such as chaining parallel tasks, dynamically adding tasks to a manager or chain based on conditions, and much more.

@push.rocks/taskbuffer leverages TypeScript's advanced typing features to provide you with clear and predictable APIs, making it easier to build and maintain complex task management logic within your application.

For further information and advanced configurations, please refer to the official documentation.

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.