Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
df18aba4b5 | |||
a3699f2869 | |||
017c0789ca | |||
6e6d056617 | |||
3f7f38ee17 | |||
5bfc72a602 |
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -2,4 +2,5 @@ export { Task, ITaskFunction } from './taskbuffer.classes.task';
|
|||||||
export { Taskchain } from './taskbuffer.classes.taskchain';
|
export { Taskchain } from './taskbuffer.classes.taskchain';
|
||||||
export { Taskparallel } from './taskbuffer.classes.taskparallel';
|
export { Taskparallel } from './taskbuffer.classes.taskparallel';
|
||||||
export { TaskManager } from './taskbuffer.classes.taskmanager';
|
export { TaskManager } from './taskbuffer.classes.taskmanager';
|
||||||
|
export { TaskOnce } from './taskbuffer.classes.taskonce';
|
||||||
import './taskbuffer.classes.helpers';
|
import './taskbuffer.classes.helpers';
|
||||||
|
4
dist/index.js
vendored
4
dist/index.js
vendored
@ -8,6 +8,8 @@ var taskbuffer_classes_taskparallel_1 = require("./taskbuffer.classes.taskparall
|
|||||||
exports.Taskparallel = taskbuffer_classes_taskparallel_1.Taskparallel;
|
exports.Taskparallel = taskbuffer_classes_taskparallel_1.Taskparallel;
|
||||||
var taskbuffer_classes_taskmanager_1 = require("./taskbuffer.classes.taskmanager");
|
var taskbuffer_classes_taskmanager_1 = require("./taskbuffer.classes.taskmanager");
|
||||||
exports.TaskManager = taskbuffer_classes_taskmanager_1.TaskManager;
|
exports.TaskManager = taskbuffer_classes_taskmanager_1.TaskManager;
|
||||||
|
var taskbuffer_classes_taskonce_1 = require("./taskbuffer.classes.taskonce");
|
||||||
|
exports.TaskOnce = taskbuffer_classes_taskonce_1.TaskOnce;
|
||||||
// import for naming only
|
// import for naming only
|
||||||
require("./taskbuffer.classes.helpers");
|
require("./taskbuffer.classes.helpers");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHFFQUE0RDtBQUFwRCx5Q0FBQSxJQUFJLENBQUE7QUFDWiwrRUFBd0Q7QUFBaEQsbURBQUEsU0FBUyxDQUFBO0FBQ2pCLHFGQUE4RDtBQUF0RCx5REFBQSxZQUFZLENBQUE7QUFDcEIsbUZBQThEO0FBQXJELHVEQUFBLFdBQVcsQ0FBQTtBQUVwQix5QkFBeUI7QUFDekIsd0NBQXFDIn0=
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHFFQUErRDtBQUF0RCx5Q0FBQSxJQUFJLENBQUE7QUFDYiwrRUFBMEQ7QUFBakQsbURBQUEsU0FBUyxDQUFBO0FBQ2xCLHFGQUFnRTtBQUF2RCx5REFBQSxZQUFZLENBQUE7QUFDckIsbUZBQThEO0FBQXJELHVEQUFBLFdBQVcsQ0FBQTtBQUNwQiw2RUFBd0Q7QUFBL0MsaURBQUEsUUFBUSxDQUFBO0FBRWpCLHlCQUF5QjtBQUN6Qix3Q0FBcUMifQ==
|
11
dist/taskbuffer.classes.taskonce.d.ts
vendored
Normal file
11
dist/taskbuffer.classes.taskonce.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Task, ITaskFunction } from './taskbuffer.classes.task';
|
||||||
|
/**
|
||||||
|
* TaskOnce is run exactly once, no matter how often it is triggered
|
||||||
|
*/
|
||||||
|
export declare class TaskOnce extends Task {
|
||||||
|
hasTriggered: boolean;
|
||||||
|
constructor(optionsArg: {
|
||||||
|
name?: string;
|
||||||
|
taskFunction: ITaskFunction;
|
||||||
|
});
|
||||||
|
}
|
30
dist/taskbuffer.classes.taskonce.js
vendored
Normal file
30
dist/taskbuffer.classes.taskonce.js
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const taskbuffer_classes_task_1 = require("./taskbuffer.classes.task");
|
||||||
|
/**
|
||||||
|
* TaskOnce is run exactly once, no matter how often it is triggered
|
||||||
|
*/
|
||||||
|
class TaskOnce extends taskbuffer_classes_task_1.Task {
|
||||||
|
constructor(optionsArg) {
|
||||||
|
super({
|
||||||
|
name: optionsArg.name,
|
||||||
|
taskFunction: () => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (!this.hasTriggered) {
|
||||||
|
this.hasTriggered = true;
|
||||||
|
yield optionsArg.taskFunction();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
this.hasTriggered = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.TaskOnce = TaskOnce;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2tvbmNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvdGFza2J1ZmZlci5jbGFzc2VzLnRhc2tvbmNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFFQSx1RUFBK0Q7QUFFL0Q7O0dBRUc7QUFDSCxjQUFzQixTQUFRLDhCQUFJO0lBRWhDLFlBQWEsVUFHWjtRQUNDLEtBQUssQ0FBQztZQUNKLElBQUksRUFBRSxVQUFVLENBQUMsSUFBSTtZQUNyQixZQUFZLEVBQUU7Z0JBQ1osRUFBRSxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsWUFBWSxDQUFDLENBQUMsQ0FBQztvQkFDdkIsSUFBSSxDQUFDLFlBQVksR0FBRyxJQUFJLENBQUE7b0JBQ3hCLE1BQU0sVUFBVSxDQUFDLFlBQVksRUFBRSxDQUFBO2dCQUNqQyxDQUFDO1lBQ0gsQ0FBQyxDQUFBO1NBQ0YsQ0FBQyxDQUFBO1FBYkosaUJBQVksR0FBWSxLQUFLLENBQUE7SUFjN0IsQ0FBQztDQUNGO0FBaEJELDRCQWdCQyJ9
|
79
docs/index.md
Normal file
79
docs/index.md
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
# 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)
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "taskbuffer",
|
"name": "taskbuffer",
|
||||||
"version": "1.0.19",
|
"version": "1.0.22",
|
||||||
"description": "flexible task management. TypeScript ready!",
|
"description": "flexible task management. TypeScript ready!",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
|
29
readme.md
Normal file
29
readme.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# 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/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
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)
|
28
test/test.6.taskonce.ts
Normal file
28
test/test.6.taskonce.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { expect, tap } from 'tapbundle'
|
||||||
|
|
||||||
|
import * as taskbuffer from '../dist/index'
|
||||||
|
|
||||||
|
let myNumber = 0
|
||||||
|
let myTaskOnce: taskbuffer.TaskOnce
|
||||||
|
|
||||||
|
tap.test('should create a valid instance of TaskOnce', async () => {
|
||||||
|
myTaskOnce = new taskbuffer.TaskOnce({
|
||||||
|
taskFunction: async () => {
|
||||||
|
myNumber++
|
||||||
|
}
|
||||||
|
})
|
||||||
|
expect(myTaskOnce).to.be.instanceof(taskbuffer.TaskOnce)
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.test('myNumber should still be 0', async () => {
|
||||||
|
expect(myNumber).to.equal(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.test('myTaskOnce should trigger once', async () => {
|
||||||
|
await myTaskOnce.trigger()
|
||||||
|
await myTaskOnce.trigger()
|
||||||
|
await myTaskOnce.trigger()
|
||||||
|
expect(myNumber).to.equal(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.start()
|
@ -2,6 +2,7 @@ export {Task,ITaskFunction} from './taskbuffer.classes.task'
|
|||||||
export { Taskchain } from './taskbuffer.classes.taskchain'
|
export { Taskchain } from './taskbuffer.classes.taskchain'
|
||||||
export { Taskparallel } from './taskbuffer.classes.taskparallel'
|
export { Taskparallel } from './taskbuffer.classes.taskparallel'
|
||||||
export { TaskManager } from './taskbuffer.classes.taskmanager'
|
export { TaskManager } from './taskbuffer.classes.taskmanager'
|
||||||
|
export { TaskOnce } from './taskbuffer.classes.taskonce'
|
||||||
|
|
||||||
// import for naming only
|
// import for naming only
|
||||||
import './taskbuffer.classes.helpers'
|
import './taskbuffer.classes.helpers'
|
||||||
|
24
ts/taskbuffer.classes.taskonce.ts
Normal file
24
ts/taskbuffer.classes.taskonce.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import * as plugins from './taskbuffer.plugins'
|
||||||
|
|
||||||
|
import { Task, ITaskFunction} from './taskbuffer.classes.task'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TaskOnce is run exactly once, no matter how often it is triggered
|
||||||
|
*/
|
||||||
|
export class TaskOnce extends Task {
|
||||||
|
hasTriggered: boolean = false
|
||||||
|
constructor (optionsArg: {
|
||||||
|
name?: string,
|
||||||
|
taskFunction: ITaskFunction
|
||||||
|
}) {
|
||||||
|
super({
|
||||||
|
name: optionsArg.name,
|
||||||
|
taskFunction: async () => {
|
||||||
|
if (!this.hasTriggered) {
|
||||||
|
this.hasTriggered = true
|
||||||
|
await optionsArg.taskFunction()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user