Compare commits

..

4 Commits

Author SHA1 Message Date
df18aba4b5 1.0.22 2017-07-12 16:45:21 +02:00
a3699f2869 introduce TaskOnce 2017-07-12 16:45:18 +02:00
017c0789ca 1.0.21 2017-07-10 14:29:02 +02:00
6e6d056617 update docs 2017-07-10 14:28:58 +02:00
10 changed files with 134 additions and 5 deletions

1
dist/index.d.ts vendored
View File

@ -2,4 +2,5 @@ export { Task, ITaskFunction } from './taskbuffer.classes.task';
export { Taskchain } from './taskbuffer.classes.taskchain';
export { Taskparallel } from './taskbuffer.classes.taskparallel';
export { TaskManager } from './taskbuffer.classes.taskmanager';
export { TaskOnce } from './taskbuffer.classes.taskonce';
import './taskbuffer.classes.helpers';

4
dist/index.js vendored
View File

@ -8,6 +8,8 @@ var taskbuffer_classes_taskparallel_1 = require("./taskbuffer.classes.taskparall
exports.Taskparallel = taskbuffer_classes_taskparallel_1.Taskparallel;
var taskbuffer_classes_taskmanager_1 = require("./taskbuffer.classes.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
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
View 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
View 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

View File

@ -61,6 +61,9 @@ 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

View File

@ -1,6 +1,6 @@
{
"name": "taskbuffer",
"version": "1.0.20",
"version": "1.0.22",
"description": "flexible task management. TypeScript ready!",
"main": "dist/index.js",
"typings": "dist/index.d.ts",

29
readme.md Normal file
View File

@ -0,0 +1,29 @@
# taskbuffer
flexible task management. TypeScript ready!
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/taskbuffer)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/taskbuffer)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/taskbuffer)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/taskbuffer/)
## Status for master
[![build status](https://GitLab.com/pushrocks/taskbuffer/badges/master/build.svg)](https://GitLab.com/pushrocks/taskbuffer/commits/master)
[![coverage report](https://GitLab.com/pushrocks/taskbuffer/badges/master/coverage.svg)](https://GitLab.com/pushrocks/taskbuffer/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/taskbuffer.svg)](https://www.npmjs.com/package/taskbuffer)
[![Dependency Status](https://david-dm.org/pushrocks/taskbuffer.svg)](https://david-dm.org/pushrocks/taskbuffer)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/taskbuffer/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/taskbuffer/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/taskbuffer/badges/code.svg)](https://www.bithound.io/github/pushrocks/taskbuffer)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](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)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

28
test/test.6.taskonce.ts Normal file
View 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()

View File

@ -1,7 +1,8 @@
export {Task,ITaskFunction} from './taskbuffer.classes.task'
export {Taskchain} from './taskbuffer.classes.taskchain'
export {Taskparallel} from './taskbuffer.classes.taskparallel'
export { Task, ITaskFunction } from './taskbuffer.classes.task'
export { Taskchain } from './taskbuffer.classes.taskchain'
export { Taskparallel } from './taskbuffer.classes.taskparallel'
export { TaskManager } from './taskbuffer.classes.taskmanager'
export { TaskOnce } from './taskbuffer.classes.taskonce'
// import for naming only
import './taskbuffer.classes.helpers'

View 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()
}
}
})
}
}