Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
9df7787450 | |||
3e81fdacad | |||
f74da6ff0b | |||
e9d976ad1e | |||
f6d314695a | |||
d35b34f4aa | |||
9fec5ce62e | |||
7577479368 |
@ -1,87 +0,0 @@
|
||||
# taskbuffer
|
||||
|
||||
flexible task management. TypeScript ready!
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/taskbuffer)
|
||||
[](https://GitLab.com/pushrocks/taskbuffer)
|
||||
[](https://github.com/pushrocks/taskbuffer)
|
||||
[](https://pushrocks.gitlab.io/taskbuffer/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/pushrocks/taskbuffer/commits/master)
|
||||
[](https://GitLab.com/pushrocks/taskbuffer/commits/master)
|
||||
[](https://www.npmjs.com/package/taskbuffer)
|
||||
[](https://david-dm.org/pushrocks/taskbuffer)
|
||||
[](https://www.bithound.io/github/pushrocks/taskbuffer/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/taskbuffer)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install taskbuffer --save
|
||||
```
|
||||
|
||||
## Concepts
|
||||
|
||||
### class `Task`
|
||||
|
||||
- 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.
|
||||
- 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.
|
||||
|
||||
### class `TaskChain`
|
||||
|
||||
- TaskChain extends Task.
|
||||
- Multiple Tasks can be combined in a bigger task using a TaskChain.
|
||||
- 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
|
||||
|
||||
### class `TaskParallel`
|
||||
|
||||
- TaskParallel extends Task.
|
||||
- like TaskChain, however **tasks run in parallel**
|
||||
- Tasks cannot rely on each other.
|
||||
|
||||
### Usage
|
||||
|
||||
We highly recommend TypeScript as this module supports **TypeScript intellisense**.
|
||||
|
||||
```javascript
|
||||
import * as taskbuffer from "taskbuffer";
|
||||
|
||||
myTask = new taskbuffer.Task({
|
||||
preTask: someOtherTask // optional, don't worry loops are prevented
|
||||
afterTask: someOtherTask // optional, don't worry loops are prevented
|
||||
name:"myTask1",
|
||||
buffered: true, // optional
|
||||
bufferMax: 3, // optional, call qeues greater than this are truncated
|
||||
execDelay: 1000, // optional, time in ms to wait before executing task call
|
||||
taskFunction:() => {
|
||||
// do some stuff and return promise
|
||||
// pass on any data through promise resolution
|
||||
// Use TypeScript for better understanding and code completion
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
|
||||
[](https://push.rocks)
|
102
package-lock.json
generated
102
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "taskbuffer",
|
||||
"version": "2.0.0",
|
||||
"name": "@pushrocks/taskbuffer",
|
||||
"version": "2.0.4",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -14,6 +14,55 @@
|
||||
"nan": "^2.9.2"
|
||||
}
|
||||
},
|
||||
"@gitzone/tsbuild": {
|
||||
"version": "2.0.22",
|
||||
"resolved": "https://registry.npmjs.org/@gitzone/tsbuild/-/tsbuild-2.0.22.tgz",
|
||||
"integrity": "sha512-H0rqGVUKXWgxXhkY62kF92WpbS9GSJW27jQXaoyMsQptTQN4HIYKHWZMdO4egkk0/gDmKnBjk8MXg5Rx6efItA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@pushrocks/smartfile": "^6.0.6",
|
||||
"@pushrocks/smartlog": "^2.0.1",
|
||||
"@pushrocks/smartpath": "^4.0.1",
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"typescript": "^3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartfile": {
|
||||
"version": "6.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartfile/-/smartfile-6.0.6.tgz",
|
||||
"integrity": "sha512-vA1+yS6n0kuBZ+Bl30rxOCYvgIj0mo9g303cUpOZR0I781iQVWHcBKRC05FaGDxJD1HuYdvbSK+7vlrzZjVcMw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@pushrocks/smartpath": "^4.0.1",
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@pushrocks/smartrequest": "^1.1.12",
|
||||
"@types/fs-extra": "^5.0.4",
|
||||
"@types/vinyl": "^2.0.2",
|
||||
"fs-extra": "^7.0.0",
|
||||
"glob": "^7.1.2",
|
||||
"js-yaml": "^3.10.0",
|
||||
"vinyl-file": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.0.tgz",
|
||||
"integrity": "sha512-EglNDLRpmaTWiD/qraZn6HREAEAHJcJOmxNEYwq6xeMKnVMAy3GUcFB+wXt2C6k4CNvB/mP1y/U3dzvKKj5OtQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.2",
|
||||
"jsonfile": "^4.0.0",
|
||||
"universalify": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.0.1.tgz",
|
||||
"integrity": "sha512-zQIMOmC+372pC/CCVLqnQ0zSBiY7HHodU7mpQdjiZddek4GMj31I3dUJ7gAs9o65X7mnRma6OokOkc6f9jjfBg==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"@gitzone/tsrun": {
|
||||
"version": "1.1.9",
|
||||
"resolved": "https://registry.npmjs.org/@gitzone/tsrun/-/tsrun-1.1.9.tgz",
|
||||
@ -26,9 +75,9 @@
|
||||
}
|
||||
},
|
||||
"@gitzone/tstest": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@gitzone/tstest/-/tstest-1.0.7.tgz",
|
||||
"integrity": "sha512-7F421u517blOgx9QtYfygSRA79aqDZqiSBAoR9YQGVTgehEnmMva7JQM50SuQxhDQ9TUEX0fPARPrZWFreZ2wg==",
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@gitzone/tstest/-/tstest-1.0.11.tgz",
|
||||
"integrity": "sha512-f07enMUm/jMVyHBK8w98DBoFhf2xo+DJKDlawDrWUTIv3mm2hQ05gmMNjmk82j9HamLcz0/sTldULHVSBaxIXw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@gitzone/tsrun": "^1.1.9",
|
||||
@ -36,7 +85,9 @@
|
||||
"@pushrocks/smartfile": "^6.0.3",
|
||||
"@pushrocks/smartlog": "^2.0.1",
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@pushrocks/smartshell": "^2.0.5"
|
||||
"@pushrocks/smartshell": "^2.0.5",
|
||||
"@types/figures": "^2.0.0",
|
||||
"figures": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"@pushrocks/consolecolor": {
|
||||
@ -99,6 +150,12 @@
|
||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-1.0.9.tgz",
|
||||
"integrity": "sha512-0qwpomrRN0kFjmhR9m1iHYXoISoNuXtRP0Wr+JtkYyURLwKHMaW8Xoznf8MzXJptRfqufJi3Fxh5HodpPrIZUA=="
|
||||
},
|
||||
"@pushrocks/smartpath": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartpath/-/smartpath-4.0.1.tgz",
|
||||
"integrity": "sha512-MaI0+uLQPCr2V3WGnbdgb0pWa9xkWyrP4qYcbsHIjeismGLbn9s3jmP/HIXU8LkgzRgaVb+BJxmZJHOwl32DyA==",
|
||||
"dev": true
|
||||
},
|
||||
"@pushrocks/smartpromise": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartpromise/-/smartpromise-2.0.5.tgz",
|
||||
@ -168,6 +225,12 @@
|
||||
"resolved": "https://registry.npmjs.org/@types/cron/-/cron-1.3.0.tgz",
|
||||
"integrity": "sha512-RNJ6Hbxs9CbUw+Bxt8kpN8/yNlYG1xli0JZSO1xTJJxFjgD2KWctFSkJeJpjf9iLJU0jeNPoJ5LEru7eBN3xuA=="
|
||||
},
|
||||
"@types/figures": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/figures/-/figures-2.0.0.tgz",
|
||||
"integrity": "sha512-mcRgJ+ncKuNI+Dwac7omO18B8C8u+YBS+AU/oyLhEyjAnT3cUUThhHgZpbiIvu5ZqSvdD30BXtrqg9nxc3OKMg==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/form-data": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-2.2.1.tgz",
|
||||
@ -187,9 +250,9 @@
|
||||
}
|
||||
},
|
||||
"@types/lodash": {
|
||||
"version": "4.14.115",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.115.tgz",
|
||||
"integrity": "sha512-9K/P4XMQxk61omAzQh3bbbFiqnG17eLcFysjlAYz0aPcYrVo8T+ujaCeIeY0Gpzux7x1YbxtEtLKB7ZWf79qdg=="
|
||||
"version": "4.14.116",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.116.tgz",
|
||||
"integrity": "sha512-lRnAtKnxMXcYYXqOiotTmJd74uawNWuPnsnPrrO7HiFuE3npE2iQhfABatbYDyxTNqZNuXzcKGhw37R7RjBFLg=="
|
||||
},
|
||||
"@types/minimatch": {
|
||||
"version": "3.0.3",
|
||||
@ -197,9 +260,9 @@
|
||||
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "10.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.4.tgz",
|
||||
"integrity": "sha512-8TqvB0ReZWwtcd3LXq3YSrBoLyXFgBX/sBZfGye9+YS8zH7/g+i6QRIuiDmwBoTzcQ/pk89nZYTYU4c5akKkzw==",
|
||||
"version": "10.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.6.tgz",
|
||||
"integrity": "sha512-c5Z1j1ysgo4878ptz6gxLcgMfJ6Wf908R3l5KAGabr0XJ72ZFmOCgsaodPpNYTfp4iOrSwgTDvR/BxbFfB4zPQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/vinyl": {
|
||||
@ -450,12 +513,27 @@
|
||||
"integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",
|
||||
"dev": true
|
||||
},
|
||||
"escape-string-regexp": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
||||
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
|
||||
"dev": true
|
||||
},
|
||||
"esprima": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
|
||||
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
|
||||
"dev": true
|
||||
},
|
||||
"figures": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz",
|
||||
"integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"escape-string-regexp": "^1.0.5"
|
||||
}
|
||||
},
|
||||
"first-chunk-stream": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/first-chunk-stream/-/first-chunk-stream-2.0.0.tgz",
|
||||
|
15
package.json
15
package.json
@ -1,12 +1,13 @@
|
||||
{
|
||||
"name": "@pushrocks/taskbuffer",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.4",
|
||||
"private": false,
|
||||
"description": "flexible task management. TypeScript ready!",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "tstest test/",
|
||||
"build": "echo \"Not needed for now\""
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -35,9 +36,9 @@
|
||||
"rxjs": "^6.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tstest": "^1.0.7",
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tstest": "^1.0.11",
|
||||
"@pushrocks/tapbundle": "^3.0.1",
|
||||
"@types/node": "^10.5.4"
|
||||
},
|
||||
"private": true
|
||||
"@types/node": "^10.5.6"
|
||||
}
|
||||
}
|
||||
|
62
readme.md
62
readme.md
@ -1,4 +1,4 @@
|
||||
# @pushrocks/taskbuffer
|
||||
# taskbuffer
|
||||
|
||||
flexible task management. TypeScript ready!
|
||||
|
||||
@ -21,13 +21,67 @@ flexible task management. TypeScript ready!
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
## Install
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
```sh
|
||||
npm install taskbuffer --save
|
||||
```
|
||||
|
||||
## Concepts
|
||||
|
||||
### class `Task`
|
||||
|
||||
- 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.
|
||||
- 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.
|
||||
|
||||
### class `TaskChain`
|
||||
|
||||
- TaskChain extends Task.
|
||||
- Multiple Tasks can be combined in a bigger task using a TaskChain.
|
||||
- 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
|
||||
|
||||
### class `TaskParallel`
|
||||
|
||||
- TaskParallel extends Task.
|
||||
- like TaskChain, however **tasks run in parallel**
|
||||
- Tasks cannot rely on each other.
|
||||
|
||||
### Usage
|
||||
|
||||
We highly recommend TypeScript as this module supports **TypeScript intellisense**.
|
||||
|
||||
```javascript
|
||||
import * as taskbuffer from "taskbuffer";
|
||||
|
||||
myTask = new taskbuffer.Task({
|
||||
preTask: someOtherTask // optional, don't worry loops are prevented
|
||||
afterTask: someOtherTask // optional, don't worry loops are prevented
|
||||
name:"myTask1",
|
||||
buffered: true, // optional
|
||||
bufferMax: 3, // optional, call qeues greater than this are truncated
|
||||
execDelay: 1000, // optional, time in ms to wait before executing task call
|
||||
taskFunction:() => {
|
||||
// do some stuff and return promise
|
||||
// pass on any data through promise resolution
|
||||
// Use TypeScript for better understanding and code completion
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://push.rocks)
|
||||
|
Reference in New Issue
Block a user