https://github.com/cadgerfeast/duncan
Great and Responsable TypeScript Chains
https://github.com/cadgerfeast/duncan
chain duncan parallel responsability sequential typescript
Last synced: 9 months ago
JSON representation
Great and Responsable TypeScript Chains
- Host: GitHub
- URL: https://github.com/cadgerfeast/duncan
- Owner: cadgerfeast
- License: mit
- Created: 2022-12-06T10:28:41.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-02-05T13:12:08.000Z (over 3 years ago)
- Last Synced: 2024-12-28T14:44:49.480Z (over 1 year ago)
- Topics: chain, duncan, parallel, responsability, sequential, typescript
- Language: TypeScript
- Homepage: https://duncan.cadgerfeast.dev
- Size: 1.1 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# duncan
[](https://sonarcloud.io/dashboard?id=cadgerfeast_duncan)
[](https://sonarcloud.io/dashboard?id=cadgerfeast_duncan)
[](https://www.npmjs.com/package/duncan)
[](https://www.npmjs.com/package/duncan)
[](https://github.com/cadgerfeast/duncan/blob/master/LICENSE)

> 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](https://refactoring.guru/design-patterns/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
``` bash
npm install duncan --save
```
## Usage
``` typescript
// 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
## License
MIT