taskbuffer/README.md

56 lines
2.1 KiB
Markdown
Raw Normal View History

2016-02-18 21:26:18 +00:00
# taskbuffer
2016-08-01 11:35:33 +00:00
flexible task management. TypeScript ready!
2016-02-18 21:26:18 +00:00
## Status
[![Coverage Status](https://coveralls.io/repos/github/pushrocks/taskbuffer/badge.svg?branch=master)](https://coveralls.io/github/pushrocks/taskbuffer?branch=master)
## Install
```sh
npm install taskbuffer --save
2016-05-04 02:11:22 +00:00
```
## Concepts
2016-05-17 01:27:29 +00:00
### class `Task`
2016-05-04 02:11:22 +00:00
* A Task in its most simple form is a function that is executed when the task runs.
* A Task can have a **preTask** and an **afterTask**
(those are run before or after the main function whenever the task is called)
* A Task can be buffered.
That means it can be called multiple times in a very short time.
However execution happens in line:
meaning execution of the task's main function is on halt until the previous task call has finished.
You can set bufferMax number, which is the max number of buffered task calls.
Any additional calls will then be truncated
* Task.trigger() and Task.triggerBuffered() always return a Promise
which is fullfilled once the related task call has completed.
2016-05-04 03:15:05 +00:00
* Task.triggered() is an Observable stream that emits events every time a task call is called and every time a call is completed.
* Task is compatible to gulp streams.
2016-05-17 01:27:29 +00:00
### class `TaskChain`
2016-05-17 01:32:47 +00:00
* TaskChain extends Task.
* Multiple Tasks can be combined in a bigger task using a TaskChain.
2016-05-17 01:27:29 +00:00
* While the tasks are async in themselve, TaskChain **runs Tasks serialized** (one after the other)
* that means that tasks can rely on each other and
2016-05-17 01:27:29 +00:00
### class `TaskParallel`
2016-05-17 01:32:47 +00:00
* TaskParallel extends Task.
2016-05-17 01:27:29 +00:00
* like TaskChain, however **tasks run in parallel**
2016-05-17 01:32:47 +00:00
* Tasks cannot rely on each other.
2016-05-17 01:27:29 +00:00
### Usage
We highly recommend TypeScript as this module supports **TypeScript intellisense**.
```
import * as taskbuffer from "taskbuffer";
myTask = new taskbuffer.Task({
2016-05-17 01:32:47 +00:00
preTask: someOtherTask // optional, don't worry loops are prevented
afterTask: someOtherTask // optional, don't worry loops are prevented
2016-05-17 01:27:29 +00:00
name:"myTask1",
taskFunction:() => {
2016-05-17 01:32:47 +00:00
// do some stuff and return promise
// pass on any data through promise resolution
// Use TypeScript for better understanding and code completion
2016-05-17 01:27:29 +00:00
}
})
```