JSPM

@taskprod/core

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q19158F
  • License MIT

A flexible pipeline executor for chaining asynchronous functions, with a shared context and middleware support for custom workflows like logging, retries, and result tracking. Ideal for automating complex tasks, processing data, or managing API requests with sequential logic and context persistence.

Package Exports

  • @taskprod/core
  • @taskprod/core/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@taskprod/core) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Taskprod: Asynchronous Function Pipeline with Middleware

Overview

taskprod is a powerful JavaScript utility for executing a series of asynchronous functions in sequence, passing the result of each function to the next while maintaining a shared context. This tool allows developers to manage complex workflows, integrate middleware for custom logic, track function results, and handle retries with exponential backoff.

Features

  • Asynchronous Pipeline: Executes async functions in sequence.
  • Shared Context: Track state and results across function calls.
  • Middleware: Add custom logic between each step.
  • Retry Mechanism: Built-in retry logic with exponential backoff.
  • Result Tracking: Log function results and history.

Installation

Install via npm:

npm install @taskprod/core

Usage

Create a pipeline of asynchronous functions and add middleware to customize behavior.

const { taskprod, retryMiddleware } = require('@taskprod/core');

// Define async functions
async function addTwo(arg, context) {
  return arg + 2;
}

async function multiplyByThree(arg, context) {
  return arg * 3;
}

// Create a pipeline with retry middleware
const result = await taskprod(addTwo, multiplyByThree)(5, {
  initialContext: { exampleKey: 'exampleValue' },
  middleware: [retryMiddleware(3, 1000, 2)],
});

console.log(result);  // Outputs: [21, updatedContext]

In this example, the pipeline runs addTwo and multiplyByThree in sequence, and uses retry middleware to handle failures.

Middleware Examples

Retry Middleware

Automatically retries failed methods with exponential backoff:

const retry = retryMiddleware(3, 1000, 2);  // 3 retries, starting at 1 second, doubling delay each retry

History Middleware

Store a deep-cloned snapshot of the context at each step:

const { historyMiddleware } = require('@taskprod/core');

Function Result Tracking

Track and store the results of each method in the context:

const { functionResultsHistoryMiddleware } = require('@taskprod/core');

Testing

Run tests using Node’s built-in testing framework:

node script.js

License

MIT License