Compare commits

..

30 Commits

Author SHA1 Message Date
af5fa857cc 2.0.16 2019-11-27 23:34:45 +00:00
f275f7e2f6 fix(core): update 2019-11-27 23:34:45 +00:00
ea1f434cdd 2.0.15 2019-09-23 18:06:43 +02:00
2cc212f210 fix(core): update 2019-09-23 18:06:43 +02:00
2d2788d1ca 2.0.14 2019-09-23 16:31:07 +02:00
de1652bac9 fix(core): update 2019-09-23 16:31:06 +02:00
5310bef1be 2.0.13 2019-09-22 15:18:28 +02:00
1a5c67efc1 2.0.12 2019-09-22 15:16:27 +02:00
df21ebd581 fix(core): update 2019-09-22 15:16:27 +02:00
3f749dfdd2 2.0.11 2019-09-18 19:15:56 +02:00
2a39543a75 fix(core): update 2019-09-18 19:15:56 +02:00
68f7d26d3b 2.0.10 2019-09-08 22:45:37 +02:00
6373a74fb3 fix(core): update 2019-09-08 22:45:36 +02:00
be3d2d41d6 2.0.9 2019-09-06 16:32:36 +02:00
2affa189a7 fix(core): update 2019-09-06 16:32:36 +02:00
8c4c2a552c 2.0.8 2019-09-05 11:35:26 +02:00
eff9c6e6c9 fix(core): update 2019-09-05 11:35:26 +02:00
4c7a373d98 2.0.7 2019-01-15 00:20:05 +01:00
6b93a2e7ac fix(core): update 2019-01-15 00:20:05 +01:00
9c6487c779 2.0.6 2019-01-15 00:17:45 +01:00
e3f37f5027 fix(core): update 2019-01-15 00:17:44 +01:00
1152bb1138 2.0.5 2018-08-12 20:55:07 +02:00
9df7787450 2.0.4 2018-08-11 00:01:19 +02:00
3e81fdacad fix(CI): now building properly 2018-08-11 00:01:19 +02:00
f74da6ff0b 2.0.3 2018-08-05 23:10:01 +02:00
e9d976ad1e fix(ci): update testing framework to the new tstest 2018-08-05 23:10:00 +02:00
f6d314695a 2.0.2 2018-08-04 18:03:23 +02:00
d35b34f4aa fix(package.json): update private param 2018-08-04 18:03:22 +02:00
9fec5ce62e 2.0.1 2018-08-04 18:02:41 +02:00
7577479368 fix(docs): update docs 2018-08-04 18:02:41 +02:00
23 changed files with 1767 additions and 846 deletions

24
.gitignore vendored
View File

@ -1,4 +1,22 @@
coverage/
node_modules
pages/
.nogit/ .nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,5 +1,5 @@
# gitzone standard # gitzone ci_default
image: hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
@ -26,6 +26,7 @@ mirror:
snyk: snyk:
stage: security stage: security
script: script:
- npmci npm prepare
- npmci command npm install -g snyk - npmci command npm install -g snyk
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command snyk test - npmci command snyk test
@ -36,44 +37,35 @@ snyk:
# ==================== # ====================
# test stage # test stage
# ==================== # ====================
testLEGACY:
stage: test
script:
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
allow_failure: true
testLTS: testStable:
stage: test
script:
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv - notpriv
release: release:
stage: release stage: release
script: script:
- npmci node install stable - npmci node install lts
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
@ -86,19 +78,11 @@ release:
# ==================== # ====================
codequality: codequality:
stage: metadata stage: metadata
image: docker:stable
allow_failure: true allow_failure: true
services:
- docker:stable-dind
script: script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') - npmci command npm install -g tslint typescript
- docker run - npmci npm install
--env SOURCE_CODE="$PWD" - npmci command "tslint -c tslint.json ./ts/**/*.ts"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
tags: tags:
- docker - docker
- priv - priv
@ -114,12 +98,15 @@ trigger:
- notpriv - notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-dbase:npmci
services:
- docker:stable-dind
stage: metadata stage: metadata
script: script:
- npmci command npm install -g typedoc typescript - npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/ - npmci command tsdoc
tags: tags:
- docker - docker
- notpriv - notpriv
@ -130,13 +117,3 @@ pages:
paths: paths:
- public - public
allow_failure: true allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

View File

@ -1,87 +0,0 @@
# 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/)
## 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)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

View File

@ -1,12 +1,17 @@
{ {
"npmts":{
"mode":"default",
"testConfig": {
"parallel": false
}
},
"npmci": { "npmci": {
"npmGlobalTools": [], "npmGlobalTools": [],
"npmAccessLevel": "public" "npmAccessLevel": "public",
"npmRegistryUrl": "registry.npmjs.org"
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "taskbuffer",
"shortDescription": "flexible task management. TypeScript ready!",
"npmPackagename": "@pushrocks/taskbuffer",
"license": "MIT"
}
} }
} }

1681
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,13 @@
{ {
"name": "@pushrocks/taskbuffer", "name": "@pushrocks/taskbuffer",
"version": "2.0.0", "version": "2.0.16",
"private": false,
"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",
"scripts": { "scripts": {
"test": "tstest test/", "test": "(tstest test/)",
"build": "echo \"Not needed for now\"" "build": "(tsbuild)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -26,18 +27,31 @@
}, },
"homepage": "https://gitlab.com/pushrocks/taskbuffer#readme", "homepage": "https://gitlab.com/pushrocks/taskbuffer#readme",
"dependencies": { "dependencies": {
"@pushrocks/lik": "^3.0.1", "@pushrocks/lik": "^3.0.13",
"@pushrocks/smartdelay": "^2.0.1", "@pushrocks/smartdelay": "^2.0.6",
"@pushrocks/smartlog": "^2.0.1", "@pushrocks/smartlog": "^2.0.21",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^3.0.6",
"@types/cron": "^1.3.0", "@types/cron": "^1.7.1",
"cron": "^1.3.0", "cron": "^1.7.2",
"rxjs": "^6.2.2" "rxjs": "^6.5.3"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tstest": "^1.0.7", "@gitzone/tsbuild": "^2.1.17",
"@pushrocks/tapbundle": "^3.0.1", "@gitzone/tstest": "^1.0.28",
"@types/node": "^10.5.4" "@pushrocks/tapbundle": "^3.2.0",
"@types/node": "^12.12.14",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0"
}, },
"private": true "files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
} }

View File

@ -1,33 +1,52 @@
# @pushrocks/taskbuffer # @pushrocks/taskbuffer
flexible task management. TypeScript ready! flexible task management. TypeScript ready!
## Availabililty ## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/taskbuffer)
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/taskbuffer) * [gitlab.com (source)](https://gitlab.com/pushrocks/taskbuffer)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/taskbuffer) * [github.com (source mirror)](https://github.com/pushrocks/taskbuffer)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/taskbuffer) * [docs (typedoc)](https://pushrocks.gitlab.io/taskbuffer/)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/taskbuffer/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/taskbuffer/badges/master/build.svg)](https://gitlab.com/pushrocks/taskbuffer/commits/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)
[![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/@pushrocks/taskbuffer.svg)](https://www.npmjs.com/package/@pushrocks/taskbuffer)
[![npm downloads per month](https://img.shields.io/npm/dm/taskbuffer.svg)](https://www.npmjs.com/package/taskbuffer) [![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/taskbuffer/badge.svg)](https://snyk.io/test/npm/@pushrocks/taskbuffer)
[![Dependency Status](https://david-dm.org/pushrocks/taskbuffer.svg)](https://david-dm.org/pushrocks/taskbuffer) [![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/taskbuffer/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/taskbuffer/master/dependencies/npm) [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![bitHound Code](https://www.bithound.io/github/pushrocks/taskbuffer/badges/code.svg)](https://www.bithound.io/github/pushrocks/taskbuffer) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
[![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 ## Usage
Use TypeScript for best in class instellisense. 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. For further information read the linked docs at the top of this README.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > 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) [![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)
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)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -8,11 +8,8 @@ import * as smartdelay from '@pushrocks/smartdelay';
let testTask: taskbuffer.Task; let testTask: taskbuffer.Task;
let testPreTask = new taskbuffer.Task({ let testPreTask = new taskbuffer.Task({
taskFunction: function() { taskFunction: async () => {
let done = smartpromise.defer();
console.log('preTask executed'); console.log('preTask executed');
done.resolve();
return done.promise;
}, },
preTask: testTask preTask: testTask
}); });
@ -35,14 +32,14 @@ let task1 = new taskbuffer.Task({
let task2 = new taskbuffer.Task({ let task2 = new taskbuffer.Task({
name: 'Task 1', name: 'Task 1',
taskFunction: () => { taskFunction: async () => {
let done = smartpromise.defer(); const done = smartpromise.defer();
console.log('Task2 started'); console.log('Task2 started');
setTimeout(() => { setTimeout(() => {
console.log('Task2 executed'); console.log('Task2 executed');
done.resolve(); done.resolve();
}, 5000); }, 5000);
return done.promise; await done.promise;
} }
}); });

View File

@ -1,11 +1,11 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import taskbuffer = require('../ts/index'); import taskbuffer = require('../ts/index');
import * as smartq from 'smartq'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@pushrocks/smartdelay';
let task1Executed = false; let task1Executed = false;
let task1 = new taskbuffer.Task({ const task1 = new taskbuffer.Task({
taskFunction: async () => { taskFunction: async () => {
await smartdelay.delayFor(2000); await smartdelay.delayFor(2000);
task1Executed = true; task1Executed = true;
@ -13,7 +13,7 @@ let task1 = new taskbuffer.Task({
}); });
let task2Executed = false; let task2Executed = false;
let task2 = new taskbuffer.Task({ const task2 = new taskbuffer.Task({
taskFunction: async () => { taskFunction: async () => {
await smartdelay.delayFor(2000); await smartdelay.delayFor(2000);
task2Executed = true; task2Executed = true;
@ -21,7 +21,7 @@ let task2 = new taskbuffer.Task({
}); });
let task3Executed = false; let task3Executed = false;
let task3 = new taskbuffer.Task({ const task3 = new taskbuffer.Task({
taskFunction: async () => { taskFunction: async () => {
await smartdelay.delayFor(2000); await smartdelay.delayFor(2000);
task3Executed = true; task3Executed = true;
@ -29,11 +29,11 @@ let task3 = new taskbuffer.Task({
}); });
tap.test('expect run tasks in sequence', async () => { tap.test('expect run tasks in sequence', async () => {
let testTaskchain = new taskbuffer.Taskchain({ const testTaskchain = new taskbuffer.Taskchain({
name: 'Taskchain1', name: 'Taskchain1',
taskArray: [task1, task2, task3] taskArray: [task1, task2, task3]
}); });
let testPromise = testTaskchain.trigger(); const testPromise = testTaskchain.trigger();
await smartdelay.delayFor(2100); await smartdelay.delayFor(2100);
// tslint:disable-next-line:no-unused-expression // tslint:disable-next-line:no-unused-expression
expect(task1Executed).to.be.true; expect(task1Executed).to.be.true;

View File

@ -1,11 +1,9 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import taskbuffer = require('../ts/index'); import taskbuffer = require('../ts/index');
import * as smartq from 'smartq';
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@pushrocks/smartdelay';
let task1Executed = false; let task1Executed = false;
let task1 = new taskbuffer.Task({ const task1 = new taskbuffer.Task({
taskFunction: async () => { taskFunction: async () => {
await smartdelay.delayFor(2000); await smartdelay.delayFor(2000);
task1Executed = true; task1Executed = true;
@ -13,7 +11,7 @@ let task1 = new taskbuffer.Task({
}); });
let task2Executed = false; let task2Executed = false;
let task2 = new taskbuffer.Task({ const task2 = new taskbuffer.Task({
taskFunction: async () => { taskFunction: async () => {
await smartdelay.delayFor(2000); await smartdelay.delayFor(2000);
task2Executed = true; task2Executed = true;
@ -21,7 +19,7 @@ let task2 = new taskbuffer.Task({
}); });
let task3Executed = false; let task3Executed = false;
let task3 = new taskbuffer.Task({ const task3 = new taskbuffer.Task({
taskFunction: async () => { taskFunction: async () => {
await smartdelay.delayFor(2000); await smartdelay.delayFor(2000);
task3Executed = true; task3Executed = true;
@ -29,7 +27,7 @@ let task3 = new taskbuffer.Task({
}); });
tap.test('expect run in Parallel', async () => { tap.test('expect run in Parallel', async () => {
let testTaskparallel = new taskbuffer.Taskparallel({ const testTaskparallel = new taskbuffer.Taskparallel({
taskArray: [task1, task2, task3] taskArray: [task1, task2, task3]
}); });
await testTaskparallel.trigger(); await testTaskparallel.trigger();

View File

@ -6,7 +6,7 @@ import * as smartdelay from '@pushrocks/smartdelay';
let myTaskManager: taskbuffer.TaskManager; let myTaskManager: taskbuffer.TaskManager;
let taskRunCounter = 0; let taskRunCounter = 0;
let taskDone = smartpromise.defer(); const taskDone = smartpromise.defer();
tap.test('should create an instance of TaskManager', async () => { tap.test('should create an instance of TaskManager', async () => {
myTaskManager = new taskbuffer.TaskManager(); myTaskManager = new taskbuffer.TaskManager();

View File

@ -4,9 +4,9 @@ import taskbuffer = require('../ts/index');
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@pushrocks/smartdelay';
let flowTask1 = new taskbuffer.Task({ const flowTask1 = new taskbuffer.Task({
taskFunction: (x: number) => { taskFunction: (x: number) => {
let done = smartpromise.defer(); const done = smartpromise.defer();
console.log('flowTask1'); console.log('flowTask1');
console.log(x); console.log(x);
done.resolve(x); done.resolve(x);
@ -14,9 +14,9 @@ let flowTask1 = new taskbuffer.Task({
} }
}); });
let flowTaskBuffered = new taskbuffer.Task({ const flowTaskBuffered = new taskbuffer.Task({
taskFunction: (x: number) => { taskFunction: (x: number) => {
let done = smartpromise.defer(); const done = smartpromise.defer();
console.log('flowTask1'); console.log('flowTask1');
console.log(x); console.log(x);
done.resolve(x); done.resolve(x);
@ -26,9 +26,9 @@ let flowTaskBuffered = new taskbuffer.Task({
bufferMax: 1 bufferMax: 1
}); });
let flowTask2 = new taskbuffer.Task({ const flowTask2 = new taskbuffer.Task({
taskFunction: (x: number) => { taskFunction: (x: number) => {
let done = smartpromise.defer(); const done = smartpromise.defer();
console.log('flowTask2'); console.log('flowTask2');
console.log(x); console.log(x);
done.resolve(x); done.resolve(x);
@ -37,27 +37,27 @@ let flowTask2 = new taskbuffer.Task({
preTask: flowTask1 preTask: flowTask1
}); });
let flowTask3 = new taskbuffer.Taskchain({ const flowTask3 = new taskbuffer.Taskchain({
taskArray: [flowTask1, flowTask2] taskArray: [flowTask1, flowTask2]
}); });
tap.test('should let a value flow through a task', async () => { tap.test('should let a value flow through a task', async () => {
let result = await flowTask1.trigger(12); const result = await flowTask1.trigger(12);
expect(result).to.equal(12); expect(result).to.equal(12);
}); });
tap.test('expect values to flow between tasks', async () => { tap.test('expect values to flow between tasks', async () => {
let result = await flowTask2.trigger(12); const result = await flowTask2.trigger(12);
expect(result).to.equal(12); expect(result).to.equal(12);
}); });
tap.test('expect values to flow between tasks when buffered', async () => { tap.test('expect values to flow between tasks when buffered', async () => {
let result = await flowTaskBuffered.trigger(12); const result = await flowTaskBuffered.trigger(12);
expect(result).to.equal(12); expect(result).to.equal(12);
}); });
tap.test('expect values to flow between tasks in Taskchain', async () => { tap.test('expect values to flow between tasks in Taskchain', async () => {
let result = await flowTask3.trigger(12); const result = await flowTask3.trigger(12);
expect(result).to.equal(12); expect(result).to.equal(12);
}); });

51
test/test.7.taskloop.ts Normal file
View File

@ -0,0 +1,51 @@
import { tap, expect } from '@pushrocks/tapbundle';
import * as taskbuffer from '../ts';
let preTask: taskbuffer.Task;
let afterTask: taskbuffer.Task;
let mainTask: taskbuffer.Task;
tap.test('should create tasks', async () => {
preTask = new taskbuffer.Task({
name: 'myPreTask',
taskFunction: async () => {
console.log('pretask executed :)');
return 'hi';
}
});
afterTask = new taskbuffer.Task({
name: 'myAfterTask',
taskFunction: async (x) => {
if (x === 'hi') {
console.log('afterTask: values get passed along alright');
}
console.log('afterTask executed :)');
return x;
},
preTask,
afterTask
});
mainTask = new taskbuffer.Task({
name: 'mainTask',
taskFunction: async (x) => {
if (x === 'hi') {
console.log('mainTask: values get passed along alright');
}
console.log('afterTask executed :)');
return x;
},
preTask: () => {
return preTask;
},
afterTask
});
});
tap.test('should execute the mainTask', async () => {
await mainTask.trigger();
});
tap.start();

View File

@ -0,0 +1,42 @@
import { Task } from "./taskbuffer.classes.task";
export class BufferRunner {
public task: Task;
// initialze by default
public bufferCounter: number = 0;
public running: boolean = false;
constructor(taskArg: Task) {
this.task = taskArg;
}
public trigger(x): Promise<any> {
if (!(this.bufferCounter >= this.task.bufferMax)) {
this.bufferCounter++;
}
const returnPromise: Promise<any> = this.task.cycleCounter.getPromiseForCycle(
this.bufferCounter + 1
);
if (!this.running) {
this._run(x);
}
return returnPromise;
}
private _run(x) {
const recursiveBufferRunner = x => {
if (this.bufferCounter >= 0) {
this.running = true;
this.task.running = true;
Task.runTask(this.task, { x: x }).then(x => {
this.bufferCounter--;
this.task.cycleCounter.informOfCycle(x);
recursiveBufferRunner(x);
});
} else {
this.running = false;
this.task.running = false;
}
};
recursiveBufferRunner(x);
}
}

View File

@ -0,0 +1,36 @@
import * as plugins from './taskbuffer.plugins';
import { Task } from './taskbuffer.classes.task';
export interface ICycleObject {
cycleCounter: number;
deferred: plugins.smartpromise.Deferred<any>;
}
export class CycleCounter {
public task: Task;
public cycleObjectArray: ICycleObject[] = [];
constructor(taskArg: Task) {
this.task = taskArg;
}
public getPromiseForCycle(cycleCountArg: number) {
const done = plugins.smartpromise.defer();
const cycleObject: ICycleObject = {
cycleCounter: cycleCountArg,
deferred: done
};
this.cycleObjectArray.push(cycleObject);
return done.promise;
}
public informOfCycle(x) {
const newCycleObjectArray: ICycleObject[] = [];
this.cycleObjectArray.forEach(cycleObjectArg => {
cycleObjectArg.cycleCounter--;
if (cycleObjectArg.cycleCounter <= 0) {
cycleObjectArg.deferred.resolve(x);
} else {
newCycleObjectArray.push(cycleObjectArg);
}
});
this.cycleObjectArray = newCycleObjectArray;
}
}

View File

@ -1,160 +1,5 @@
import plugins = require('./taskbuffer.plugins'); import plugins = require('./taskbuffer.plugins');
import { Task, ITaskFunction } from './taskbuffer.classes.task'; import { Task, ITaskFunction } from './taskbuffer.classes.task';
export let emptyTaskFunction: ITaskFunction = function(x) {
let done = plugins.smartpromise.defer();
done.resolve();
return done.promise;
};
export let isTask = function(taskArg: Task): boolean {
if (taskArg instanceof Task && typeof taskArg.taskFunction === 'function') {
return true;
} else {
return false;
}
};
export let isTaskTouched = (taskArg: Task, touchedTasksArray: Task[]): boolean => {
let result = false;
for (let keyArg in touchedTasksArray) {
if (taskArg === touchedTasksArray[keyArg]) {
result = true;
}
}
return result;
};
export let runTask = async (taskArg: Task, optionsArg: { x?; touchedTasksArray?: Task[] }) => {
let done = plugins.smartpromise.defer();
// pay respect to execDelay
if (taskArg.execDelay) {
await plugins.smartdelay.delayFor(taskArg.execDelay);
}
// set running params
taskArg.running = true;
done.promise.then(async () => {
taskArg.running = false;
});
// handle options
let options = {
...{ x: undefined, touchedTasksArray: [] },
...optionsArg
};
let x = options.x;
let touchedTasksArray: Task[] = options.touchedTasksArray;
touchedTasksArray.push(taskArg);
// run the task cascade
let localDeferred = plugins.smartpromise.defer();
localDeferred.promise
.then(() => {
if (taskArg.preTask && !isTaskTouched(taskArg.preTask, touchedTasksArray)) {
return runTask(taskArg.preTask, { x: x, touchedTasksArray: touchedTasksArray });
} else {
let done2 = plugins.smartpromise.defer();
done2.resolve(x);
return done2.promise;
}
})
.then(x => {
return taskArg.taskFunction(x);
})
.then(x => {
if (taskArg.afterTask && !isTaskTouched(taskArg.afterTask, touchedTasksArray)) {
return runTask(taskArg.afterTask, { x: x, touchedTasksArray: touchedTasksArray });
} else {
let done2 = plugins.smartpromise.defer();
done2.resolve(x);
return done2.promise;
}
})
.then(x => {
done.resolve(x);
})
.catch(err => {
console.log(err);
});
localDeferred.resolve();
return await done.promise;
};
export interface cycleObject {
cycleCounter: number;
deferred: plugins.smartpromise.Deferred<any>;
}
export class CycleCounter {
task: Task;
cycleObjectArray: cycleObject[] = [];
constructor(taskArg: Task) {
this.task = taskArg;
}
getPromiseForCycle(cycleCountArg: number) {
let done = plugins.smartpromise.defer();
let cycleObject: cycleObject = {
cycleCounter: cycleCountArg,
deferred: done
};
this.cycleObjectArray.push(cycleObject);
return done.promise;
}
informOfCycle(x) {
let newCycleObjectArray: cycleObject[] = [];
this.cycleObjectArray.forEach(cycleObjectArg => {
cycleObjectArg.cycleCounter--;
if (cycleObjectArg.cycleCounter <= 0) {
cycleObjectArg.deferred.resolve(x);
} else {
newCycleObjectArray.push(cycleObjectArg);
}
});
this.cycleObjectArray = newCycleObjectArray;
}
}
export class BufferRunner {
task: Task;
// initialze by default
bufferCounter: number = 0;
running: boolean = false;
constructor(taskArg: Task) {
this.task = taskArg;
}
trigger(x): Promise<any> {
if (!(this.bufferCounter >= this.task.bufferMax)) {
this.bufferCounter++;
}
let returnPromise: Promise<any> = this.task.cycleCounter.getPromiseForCycle(
this.bufferCounter + 1
);
if (!this.running) {
this._run(x);
}
return returnPromise;
}
private _run(x) {
let recursiveBufferRunner = x => {
if (this.bufferCounter >= 0) {
this.running = true;
this.task.running = true;
runTask(this.task, { x: x }).then(x => {
this.bufferCounter--;
this.task.cycleCounter.informOfCycle(x);
recursiveBufferRunner(x);
});
} else {
this.running = false;
this.task.running = false;
}
};
recursiveBufferRunner(x);
}
}

View File

@ -1,29 +1,142 @@
import * as plugins from './taskbuffer.plugins'; import * as plugins from './taskbuffer.plugins';
import * as helpers from './taskbuffer.classes.helpers'; import * as helpers from './taskbuffer.classes.helpers';
import { BufferRunner } from './taskbuffer.classes.bufferrunner';
import { CycleCounter } from './taskbuffer.classes.cyclecounter';
export interface ITaskFunction { export interface ITaskFunction {
(x?: any): PromiseLike<any>; (x?: any): PromiseLike<any>;
} }
export class Task { export type TPreOrAfterTaskFunction = () => Task;
// man datory properties
name: string;
taskFunction: ITaskFunction;
buffered: boolean;
bufferMax: number; export class Task {
execDelay: number; // STATIC
public static extractTask(preOrAfterTaskArg: Task | TPreOrAfterTaskFunction): Task {
switch(true) {
case (!preOrAfterTaskArg):
return null;
case (preOrAfterTaskArg instanceof Task):
return preOrAfterTaskArg as Task;
case typeof preOrAfterTaskArg === "function":
const taskFunction = preOrAfterTaskArg as TPreOrAfterTaskFunction;
return taskFunction();
default:
return null;
}
}
public static emptyTaskFunction: ITaskFunction = function(x) {
const done = plugins.smartpromise.defer();
done.resolve();
return done.promise;
};
public static isTask = (taskArg: Task): boolean => {
if (taskArg instanceof Task && typeof taskArg.taskFunction === 'function') {
return true;
} else {
return false;
}
};
public static isTaskTouched = (taskArg: Task | TPreOrAfterTaskFunction, touchedTasksArray: Task[]): boolean => {
const taskToCheck = Task.extractTask(taskArg);
let result = false;
for (const keyArg in touchedTasksArray) {
if (taskToCheck === touchedTasksArray[keyArg]) {
result = true;
}
}
return result;
};
public static runTask = async (taskArg: Task | TPreOrAfterTaskFunction, optionsArg: { x?; touchedTasksArray?: Task[] }) => {
const taskToRun = Task.extractTask(taskArg);
const done = plugins.smartpromise.defer();
// pay respect to execDelay
if (taskToRun.execDelay) {
await plugins.smartdelay.delayFor(taskToRun.execDelay);
}
// set running params
taskToRun.running = true;
done.promise.then(async () => {
taskToRun.running = false;
});
// handle options
const options = {
...{ x: undefined, touchedTasksArray: [] },
...optionsArg
};
const x = options.x;
const touchedTasksArray: Task[] = options.touchedTasksArray;
touchedTasksArray.push(taskToRun);
// run the task cascade
const localDeferred = plugins.smartpromise.defer();
localDeferred.promise
.then(() => {
// lets run any preTask
if (taskToRun.preTask && !Task.isTaskTouched(taskToRun.preTask, touchedTasksArray)) {
return Task.runTask(taskToRun.preTask, { x, touchedTasksArray });
} else {
const done2 = plugins.smartpromise.defer();
done2.resolve(x);
return done2.promise;
}
})
.then(async x => {
// lets run the main task
try {
return await taskToRun.taskFunction(x);
} catch (e) {
console.log(e);
}
})
.then(x => {
if (taskToRun.afterTask && !Task.isTaskTouched(taskToRun.afterTask, touchedTasksArray)) {
return Task.runTask(taskToRun.afterTask, { x: x, touchedTasksArray: touchedTasksArray });
} else {
const done2 = plugins.smartpromise.defer();
done2.resolve(x);
return done2.promise;
}
})
.then(x => {
done.resolve(x);
})
.catch(err => {
console.log(err);
});
localDeferred.resolve();
return await done.promise;
}
// INSTANCE
// man datory properties
public name: string;
public taskFunction: ITaskFunction;
public buffered: boolean;
public bufferMax: number;
public execDelay: number;
// tasks to run before and after // tasks to run before and after
preTask: Task; public preTask: Task | TPreOrAfterTaskFunction;
afterTask: Task; public afterTask: Task | TPreOrAfterTaskFunction;
// initialize by default // initialize by default
running: boolean = false; public running: boolean = false;
bufferRunner = new helpers.BufferRunner(this); public bufferRunner = new BufferRunner(this);
cycleCounter = new helpers.CycleCounter(this); public cycleCounter = new CycleCounter(this);
idle: boolean = true; public idle: boolean = true;
private _state: string = 'ready'; private _state: string = 'ready';
constructor(optionsArg: { constructor(optionsArg: {
@ -34,11 +147,11 @@ export class Task {
/** /**
* any other task to run before * any other task to run before
*/ */
preTask?: Task; preTask?: Task | TPreOrAfterTaskFunction;
/** /**
* any other task to run after * any other task to run after
*/ */
afterTask?: Task; afterTask?: Task | TPreOrAfterTaskFunction;
/** /**
* wether this task should run buffered * wether this task should run buffered
*/ */
@ -70,7 +183,7 @@ export class Task {
/** /**
* trigger the task. Will trigger buffered if this.buffered is true * trigger the task. Will trigger buffered if this.buffered is true
*/ */
trigger(x?): Promise<any> { public trigger(x?): Promise<any> {
if (this.buffered) { if (this.buffered) {
return this.triggerBuffered(x); return this.triggerBuffered(x);
} else { } else {
@ -81,14 +194,14 @@ export class Task {
/** /**
* trigger task unbuffered. * trigger task unbuffered.
*/ */
triggerUnBuffered(x?): Promise<any> { public triggerUnBuffered(x?): Promise<any> {
return helpers.runTask(this, { x: x }); return Task.runTask(this, { x: x });
} }
/** /**
* trigger task buffered. * trigger task buffered.
*/ */
triggerBuffered(x?): Promise<any> { public triggerBuffered(x?): Promise<any> {
return this.bufferRunner.trigger(x); return this.bufferRunner.trigger(x);
} }
@ -100,7 +213,7 @@ export class Task {
if (stateArg === 'locked') { if (stateArg === 'locked') {
this._state = 'locked'; this._state = 'locked';
} else { } else {
plugins.smartlog.defaultLogger.error('state type ' + stateArg + ' could not be set'); plugins.smartlog.defaultLogger.log('error', 'state type ' + stateArg + ' could not be set');
} }
} }
} }

View File

@ -29,7 +29,7 @@ export class Taskchain extends Task {
if (typeof this.taskArray[taskCounter] !== 'undefined') { if (typeof this.taskArray[taskCounter] !== 'undefined') {
console.log(this.name + ' running: Task' + this.taskArray[taskCounter].name); console.log(this.name + ' running: Task' + this.taskArray[taskCounter].name);
this.taskArray[taskCounter].trigger(x).then(x => { this.taskArray[taskCounter].trigger(x).then(x => {
plugins.smartlog.defaultLogger.info(this.taskArray[taskCounter].name); plugins.smartlog.defaultLogger.log('info', this.taskArray[taskCounter].name);
taskCounter++; taskCounter++;
iterateTasks(x); iterateTasks(x);
}); });

View File

@ -1,12 +1,16 @@
import * as plugins from './taskbuffer.plugins'; import * as plugins from './taskbuffer.plugins';
import { Task } from './taskbuffer.classes.task'; import { Task } from './taskbuffer.classes.task';
// interfaces export interface ICronJob {
import { Objectmap } from '@pushrocks/lik'; cronString: string;
taskNameArg: string;
job: any;
}
export class TaskManager { export class TaskManager {
taskMap = new plugins.lik.Objectmap<Task>(); public taskMap = new plugins.lik.Objectmap<Task>();
private cronJobMap = new plugins.lik.Objectmap<ICronJob>(); private cronJobMap = new plugins.lik.Objectmap<ICronJob>();
constructor() { constructor() {
// nothing here // nothing here
} }
@ -15,7 +19,7 @@ export class TaskManager {
* checks if a task is already present * checks if a task is already present
* @param taskNameArg * @param taskNameArg
*/ */
getTaskByName(taskNameArg): Task { public getTaskByName(taskNameArg): Task {
return this.taskMap.find(itemArg => { return this.taskMap.find(itemArg => {
return itemArg.name === taskNameArg; return itemArg.name === taskNameArg;
}); });
@ -25,7 +29,7 @@ export class TaskManager {
* adds a Task to the TaskManager * adds a Task to the TaskManager
* @param taskArg * @param taskArg
*/ */
addTask(taskArg: Task): void { public addTask(taskArg: Task): void {
if (!taskArg.name) { if (!taskArg.name) {
throw new Error('taskArg needs a name to be added to taskManager'); throw new Error('taskArg needs a name to be added to taskManager');
} }
@ -37,9 +41,9 @@ export class TaskManager {
* @param taskArg * @param taskArg
* @param cronStringArg * @param cronStringArg
*/ */
addAndScheduleTask(taskArg: Task, cronStringArg: string) { public addAndScheduleTask(taskArg: Task, cronStringArg: string) {
this.addTask(taskArg); this.addTask(taskArg);
let taskName = taskArg.name; const taskName = taskArg.name;
this.scheduleTaskByName(taskName, cronStringArg); this.scheduleTaskByName(taskName, cronStringArg);
} }
@ -47,21 +51,25 @@ export class TaskManager {
* triggers a task in the TaskManagerByName * triggers a task in the TaskManagerByName
* @param taskNameArg * @param taskNameArg
*/ */
triggerTaskByName(taskNameArg: string): Promise<any> { public triggerTaskByName(taskNameArg: string): Promise<any> {
let taskToTrigger = this.getTaskByName(taskNameArg); const taskToTrigger = this.getTaskByName(taskNameArg);
if (!taskToTrigger) { if (!taskToTrigger) {
throw new Error(`There is no task with the name of ${taskNameArg}`); throw new Error(`There is no task with the name of ${taskNameArg}`);
} }
return taskToTrigger.trigger(); return taskToTrigger.trigger();
} }
public async triggerTask(task: Task) {
return task.trigger();
}
/** /**
* schedules the task by name * schedules the task by name
* @param taskNameArg * @param taskNameArg
*/ */
scheduleTaskByName(taskNameArg: string, cronStringArg: string) { public scheduleTaskByName(taskNameArg: string, cronStringArg: string) {
let taskToSchedule = this.getTaskByName(taskNameArg); const taskToSchedule = this.getTaskByName(taskNameArg);
let job = new plugins.cron.CronJob({ const job = new plugins.cron.CronJob({
cronTime: cronStringArg, cronTime: cronStringArg,
onTick: () => { onTick: () => {
this.triggerTaskByName(taskNameArg); this.triggerTaskByName(taskNameArg);
@ -71,25 +79,31 @@ export class TaskManager {
this.cronJobMap.add({ this.cronJobMap.add({
taskNameArg: taskToSchedule.name, taskNameArg: taskToSchedule.name,
cronString: cronStringArg, cronString: cronStringArg,
job: job job
}); });
} }
descheduleTaskByName(taskNameArg: string) { /**
let descheduledCron = this.cronJobMap.findOneAndRemove(itemArg => { * deschedules a task by name
* @param taskNameArg
*/
public descheduleTaskByName(taskNameArg: string) {
const descheduledCron = this.cronJobMap.findOneAndRemove(itemArg => {
return itemArg.taskNameArg === taskNameArg; return itemArg.taskNameArg === taskNameArg;
}); });
descheduledCron.job.stop(); descheduledCron.job.stop();
} }
/**
* deschedules a task
* @param task
*/
public async descheduleTask(task: Task) {
await this.descheduleTaskByName(task.name);
}
/** /**
* returns all schedules of a specific task * returns all schedules of a specific task
* @param taskNameArg * @param taskNameArg
*/ */
getSchedulesForTaskName(taskNameArg: string) {} public getSchedulesForTaskName(taskNameArg: string) {}
}
export interface ICronJob {
cronString: string;
taskNameArg: string;
job: any;
} }

View File

@ -3,14 +3,14 @@ import * as helpers from './taskbuffer.classes.helpers';
import { Task } from './taskbuffer.classes.task'; import { Task } from './taskbuffer.classes.task';
export class Taskparallel extends Task { export class Taskparallel extends Task {
taskArray: Task[]; public taskArray: Task[];
constructor(optionsArg: { taskArray: Task[] }) { constructor(optionsArg: { taskArray: Task[] }) {
const options = { const options = {
...optionsArg, ...optionsArg,
...{ ...{
taskFunction: () => { taskFunction: () => {
let done = plugins.smartpromise.defer(); const done = plugins.smartpromise.defer();
let promiseArray: Promise<any>[] = []; // stores promises of all tasks, since they run in parallel const promiseArray: Promise<any>[] = []; // stores promises of all tasks, since they run in parallel
this.taskArray.forEach(function(taskArg) { this.taskArray.forEach(function(taskArg) {
promiseArray.push(taskArg.trigger()); promiseArray.push(taskArg.trigger());
}); });

View File

@ -0,0 +1,48 @@
import * as plugins from './taskbuffer.plugins';
import { Task } from './taskbuffer.classes.task';
export class TaskRunner {
public maxParrallelJobs: number = 1;
public status: 'stopped' | 'running' = 'stopped';
public runningTasks: plugins.lik.Objectmap<Task> = new plugins.lik.Objectmap<Task>();
public qeuedTasks: Task[] = [];
/**
* adds a task to the qeue
*/
public addTask(taskArg: Task) {
this.qeuedTasks.push(taskArg);
}
/**
* set amount of parallel tasks
* be careful, you might loose dependability of tasks
*/
public setMaxParallelJobs(maxParrallelJobsArg: number) {
this.maxParrallelJobs = maxParrallelJobsArg;
}
/**
* starts the task queue
*/
public start() {
this.status = 'running';
}
public async checkExecution() {
if (this.runningTasks.getArray().length < this.maxParrallelJobs) {
const nextJob = this.qeuedTasks.shift();
this.runningTasks.add(nextJob);
await nextJob.trigger();
}
}
/**
* stops the task queue
*/
public stop() {
this.status = 'stopped';
};
}

View File

@ -1,5 +1,5 @@
import * as smartlog from '@pushrocks/smartlog'; import * as smartlog from '@pushrocks/smartlog';
let cron = require('cron'); import cron from 'cron';
import * as lik from '@pushrocks/lik'; import * as lik from '@pushrocks/lik';
import * as rxjs from 'rxjs'; import * as rxjs from 'rxjs';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';

View File

@ -1,3 +1,17 @@
{ {
"extends": "tslint-config-standard" "extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
} }