duncan
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 |
License
MIT