duncan
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

duncan

Quality Gate Status Coverage Version Downloads License


Duncan Icon

Great and Responsable TypeScript Chains

Duncan is a JavaScript library that allows to organize asynchronous operations under a set of commands to be executed sequentially, or in parallel.

The library is heavily inspired by the Chain of Responsibility pattern, except it also allows to have chains in parallel.

In short, Duncan let's you organise asynchronous operations just like you would inside a Pipeline.

Installation

npm install duncan --save

Usage

// Import the library
import * as Duncan from 'duncan';

// Define commands
const myFirstCommand = new Duncan.Command({
  name: 'My First Command',
  async handler (context) {
    // Do something awesome
    return context;
  }
});
const mySecondCommand = new Duncan.Command({
  name: 'My Second Command',
  async handler (context) {
    // Do something even more awesome
    return context;
  }
});
// Define a sequential chain
const mySequentialChain = new Duncan.SequentialChain({
  name: 'My Sequential Chain',
  handlers: [
    myFirstCommand,
    mySecondCommand
  ]
});
await mySequentialChain.execute();
// Define a parallel chain
const myParallelChain = new Duncan.ParallelChain({
  name: 'My Sequential Chain',
  handlers: [
    myFirstCommand,
    mySecondCommand
  ]
});
await myParallelChain.execute();

Contributors

cadgerfeast
cadgerfeast

License

MIT

Package Sidebar

Install

npm i duncan

Weekly Downloads

2

Version

0.0.4

License

MIT

Unpacked Size

47 kB

Total Files

22

Last publish

Collaborators

  • cadgerfeast