Compare commits

..

28 Commits

Author SHA1 Message Date
b1eeb3563e 0.1.0 2016-05-15 03:18:19 +02:00
1714f552ac now has working taskchain 2016-05-15 03:16:50 +02:00
454a999a42 improve options handling between classes 2016-05-14 23:24:11 +02:00
1f3f2ae92f included ora and introduced taskspace. 2016-05-14 04:28:22 +02:00
9014eec9f6 tiny fix 2016-05-13 05:14:29 +02:00
ee56b6f655 now has working task class 2016-05-06 02:05:45 +02:00
55ddbece13 update tests 2016-05-05 19:30:24 +02:00
130c4177a6 0.0.5 2016-05-05 19:26:02 +02:00
90c9f23c23 improved .npmignore 2016-05-05 19:25:59 +02:00
0d0ee67ca3 compiled 2016-05-05 19:21:50 +02:00
5fd11ec9c0 add some more buffer logic 2016-05-05 19:21:01 +02:00
569cb311c9 compile and update some imports to work with TypeScript declaration 2016-05-05 18:36:31 +02:00
44db37574c now running Tasks and handling task loops allright. 2016-05-05 18:06:04 +02:00
fb7f5c5e68 recompile 2016-05-04 05:20:51 +02:00
b6595ac1d3 small typo fix 2016-05-04 05:15:05 +02:00
3f3f9c68f1 small update on promise return in README 2016-05-04 05:13:36 +02:00
48c20c081f update README on how buffered Tasks work. 2016-05-04 05:11:08 +02:00
72504d7ad7 cleanup 2016-05-04 04:42:47 +02:00
370e714fe1 0.0.4 2016-05-04 04:29:35 +02:00
4179347f26 fix package.json 2016-05-04 04:29:27 +02:00
130e071a06 update structure and deps 2016-05-04 04:28:50 +02:00
c4e2021a01 0.0.3 2016-05-04 04:18:11 +02:00
58ac5745a1 Update Readme and clarify use of Promises. 2016-05-04 04:17:59 +02:00
38d02a3ac2 0.0.2 2016-05-04 04:11:46 +02:00
e29f5d1633 Update Readme 2016-05-04 04:11:22 +02:00
f815773ba3 some cosmetic additions 2016-05-04 03:45:52 +02:00
771539dae3 update structure for better ES6 support 2016-05-04 03:44:54 +02:00
71c883609b update to current status 2016-05-04 02:49:43 +02:00
36 changed files with 753 additions and 188 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.idea/
coverage/
docs/
ts/*.js
ts/*.js.map
ts/typings/

View File

@ -0,0 +1,5 @@
.idea/
docs/
coverage/
ts/
node_modules/

View File

@ -8,4 +8,25 @@ Flexible task organization for gulp.
```sh
npm install taskbuffer --save
```
```
## Concepts
#### 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.
#### Taskchain
* Multiple Tasks can be combined in a bigger task using a Taskchain. Taskchain extends Task.

2
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
export * from "./taskbuffer.classes";
import "./taskbuffer.classes.helpers";

17
dist/index.js vendored
View File

@ -1,9 +1,10 @@
#!/usr/bin/env node
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
/// <reference path="./typings/main.d.ts" />
__export(require("./taskbuffer.classes"));
// import for naming only
require("./taskbuffer.classes.helpers");
var task = require("./taskbuffer.task");
var taskbuffer = {
task: task
};
module.exports = taskbuffer;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUdBLElBQU8sSUFBSSxXQUFXLG1CQUFtQixDQUFDLENBQUM7QUFHM0MsSUFBSSxVQUFVLEdBQUc7SUFDYixJQUFJLEVBQUUsSUFBSTtDQUNiLENBQUM7QUFFRixpQkFBUyxVQUFVLENBQUMiLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzQ29udGVudCI6WyIvLy8gPHJlZmVyZW5jZSBwYXRoPVwiLi90eXBpbmdzL21haW4uZC50c1wiIC8+XG5pbXBvcnQgcGx1Z2lucyA9IHJlcXVpcmUoXCIuL3Rhc2tidWZmZXIucGx1Z2luc1wiKTtcbmltcG9ydCBjbGFzc2VzID0gcmVxdWlyZShcIi4vdGFza2J1ZmZlci5jbGFzc2VzXCIpO1xuaW1wb3J0IHRhc2sgPSByZXF1aXJlKFwiLi90YXNrYnVmZmVyLnRhc2tcIik7XG5pbXBvcnQgdGFza2NoYWluID0gcmVxdWlyZShcIi4vdGFza2J1ZmZlci50YXNrY2hhaW5cIik7XG5cbnZhciB0YXNrYnVmZmVyID0ge1xuICAgIHRhc2s6IHRhc2tcbn07XG5cbmV4cG9ydCA9IHRhc2tidWZmZXI7Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7QUFBQSw0Q0FBNEM7QUFDNUMsaUJBQWMsc0JBQXNCLENBQUMsRUFBQTtBQUVyQyx5QkFBeUI7QUFDekIsUUFBTyw4QkFBOEIsQ0FBQyxDQUFEIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxyXG5leHBvcnQgKiBmcm9tIFwiLi90YXNrYnVmZmVyLmNsYXNzZXNcIjtcclxuXHJcbi8vIGltcG9ydCBmb3IgbmFtaW5nIG9ubHlcclxuaW1wb3J0IFwiLi90YXNrYnVmZmVyLmNsYXNzZXMuaGVscGVyc1wiIl19

2
dist/taskbuffer.classes.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
export * from "./taskbuffer.classes.task";
export * from "./taskbuffer.classes.taskchain";

9
dist/taskbuffer.classes.helpers.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
import { Task } from "./taskbuffer.classes";
export declare let emptyTaskFunction: () => any;
export declare let isTask: (taskArg: any) => boolean;
export declare let isTaskTouched: (taskArg: Task, touchedTasksArray: Task[]) => boolean;
export declare let runTask: (taskArg: Task, optionsArg?: {
touchedTasksArray: Task[];
}) => any;
export declare let runBufferedTask: (taskArg: Task) => void;
export declare let updateTaskStatus: (taskArg: any, statusArg: string) => void;

96
dist/taskbuffer.classes.helpers.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,52 +1,8 @@
#!/usr/bin/env node
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(require("./taskbuffer.classes.task"));
__export(require("./taskbuffer.classes.taskchain"));
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/// <reference path="./typings/main.d.ts" />
var plugins = require("./taskbuffer.plugins");
var Task = (function () {
function Task(taskArg, optionsArg) {
this.task = taskArg;
}
Task.prototype.trigger = function () {
this.preTask.task()
.then(this.task)
.then(this.afterTask.task);
};
;
Task.prototype.triggerBuffered = function () {
var done = plugins.Q.defer();
};
Object.defineProperty(Task.prototype, "state", {
get: function () {
return this._state;
},
set: function (stateArg) {
if (stateArg == "locked") {
this._state = "locked";
}
else {
plugins.beautylog.error("state type");
}
},
enumerable: true,
configurable: true
});
return Task;
})();
exports.Task = Task;
var TaskChain = (function (_super) {
__extends(TaskChain, _super);
function TaskChain(taskArrayArg) {
_super.call(this, {
task: function () { }
});
}
return TaskChain;
})(Task);
exports.TaskChain = TaskChain;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIuY2xhc3Nlcy50cyJdLCJuYW1lcyI6WyJUYXNrIiwiVGFzay5jb25zdHJ1Y3RvciIsIlRhc2sudHJpZ2dlciIsIlRhc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nlcy5qcyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCAqIGZyb20gXCIuL3Rhc2tidWZmZXIuY2xhc3Nlcy50YXNrXCJcclxuZXhwb3J0ICogZnJvbSBcIi4vdGFza2J1ZmZlci5jbGFzc2VzLnRhc2tjaGFpblwiXHJcbiJdfQ==

25
dist/taskbuffer.classes.task.d.ts vendored Normal file
View File

@ -0,0 +1,25 @@
export declare class Task {
name: string;
task: any;
running: boolean;
idle: boolean;
buffered: boolean;
bufferCounter: number;
bufferMax: number;
private _counterTriggerAbsolute;
private _state;
preTask: Task;
afterTask: Task;
constructor(optionsArg: {
taskFunction: any;
preTask?: Task;
afterTask?: Task;
buffered?: boolean;
bufferMax?: number;
name?: string;
});
trigger(): any;
triggerUnBuffered(): any;
triggerBuffered(): any;
state: string;
}

64
dist/taskbuffer.classes.task.js vendored Normal file

File diff suppressed because one or more lines are too long

14
dist/taskbuffer.classes.taskchain.d.ts vendored Normal file
View File

@ -0,0 +1,14 @@
import { Task } from "./taskbuffer.classes";
export declare class Taskchain extends Task {
taskArray: Task[];
private _oraObject;
constructor(optionsArg: {
name?: string;
log?: boolean;
taskArray: Task[];
});
addTask(taskArg: Task): void;
removeTask(taskArg: Task): void;
shiftTask(): void;
trigger(): any;
}

70
dist/taskbuffer.classes.taskchain.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

3
dist/taskbuffer.classes.taskspace.js vendored Normal file
View File

@ -0,0 +1,3 @@
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJ0YXNrYnVmZmVyLmNsYXNzZXMudGFza3NwYWNlLmpzIiwic291cmNlc0NvbnRlbnQiOltdfQ==

3
dist/taskbuffer.plugins.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export import beautylog = require("beautylog");
export declare let Q: any;
export declare let lodash: any;

View File

@ -1,10 +1,7 @@
#!/usr/bin/env node
"use strict";
/// <reference path="./typings/main.d.ts" />
var plugins = {
beautylog: require("beautylog"),
Q: require("q")
};
module.exports = plugins;
exports.beautylog = require("beautylog");
exports.Q = require("q");
exports.lodash = require("lodash");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSw0Q0FBNEM7QUFDNUMsSUFBSSxPQUFPLEdBQUc7SUFDVixTQUFTLEVBQUUsT0FBTyxDQUFDLFdBQVcsQ0FBQztJQUMvQixDQUFDLEVBQUUsT0FBTyxDQUFDLEdBQUcsQ0FBQztDQUNsQixDQUFDO0FBQ0YsaUJBQVMsT0FBTyxDQUFDIiwiZmlsZSI6InRhc2tidWZmZXIucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbnZhciBwbHVnaW5zID0ge1xuICAgIGJlYXV0eWxvZzogcmVxdWlyZShcImJlYXV0eWxvZ1wiKSxcbiAgICBROiByZXF1aXJlKFwicVwiKVxufTtcbmV4cG9ydCA9IHBsdWdpbnM7XG4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsNENBQTRDO0FBQzlCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDcEMsU0FBQyxHQUFHLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNqQixjQUFNLEdBQUUsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDIiwiZmlsZSI6InRhc2tidWZmZXIucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cclxuZXhwb3J0IGltcG9ydCBiZWF1dHlsb2cgPSByZXF1aXJlKFwiYmVhdXR5bG9nXCIpO1xyXG5leHBvcnQgbGV0IFEgPSByZXF1aXJlKFwicVwiKTtcclxuZXhwb3J0IGxldCBsb2Rhc2g9IHJlcXVpcmUoXCJsb2Rhc2hcIik7XHJcbiJdfQ==

View File

@ -1,5 +0,0 @@
#!/usr/bin/env node
/// <reference path="./typings/main.d.ts" />
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIucHJvbWlzZWNoYWluLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDRDQUE0QyIsImZpbGUiOiJ0YXNrYnVmZmVyLnByb21pc2VjaGFpbi5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

View File

@ -1,11 +0,0 @@
#!/usr/bin/env node
/// <reference path="./typings/main.d.ts" />
var classes = require("./taskbuffer.classes");
var task = function (taskArg, options) {
var task = taskArg;
return new classes.Task(task, options);
};
module.exports = task;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIudGFzay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSw0Q0FBNEM7QUFDNUMsSUFBTyxPQUFPLFdBQVcsc0JBQXNCLENBQUMsQ0FBQztBQUNqRCxJQUFJLElBQUksR0FBRyxVQUFTLE9BQU8sRUFBQyxPQUFRO0lBQ2hDLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQTtJQUNsQixNQUFNLENBQUMsSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksRUFBQyxPQUFPLENBQUMsQ0FBQztBQUMxQyxDQUFDLENBQUM7QUFDRixpQkFBUyxJQUFJLENBQUMiLCJmaWxlIjoidGFza2J1ZmZlci50YXNrLmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxuaW1wb3J0IGNsYXNzZXMgPSByZXF1aXJlKFwiLi90YXNrYnVmZmVyLmNsYXNzZXNcIik7XG52YXIgdGFzayA9IGZ1bmN0aW9uKHRhc2tBcmcsb3B0aW9ucz8pe1xuICAgIHZhciB0YXNrID0gdGFza0FyZ1xuICAgIHJldHVybiBuZXcgY2xhc3Nlcy5UYXNrKHRhc2ssb3B0aW9ucyk7XG59O1xuZXhwb3J0ID0gdGFzazsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

View File

@ -1,10 +0,0 @@
#!/usr/bin/env node
/// <reference path="./typings/main.d.ts" />
var classes = require("./taskbuffer.classes");
var taskChain = function (taskArrayArg) {
return new classes.TaskChain(taskArrayArg);
};
module.exports = taskChain;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIudGFza2NoYWluLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDRDQUE0QztBQUM1QyxJQUFPLE9BQU8sV0FBVyxzQkFBc0IsQ0FBQyxDQUFDO0FBQ2pELElBQUksU0FBUyxHQUFHLFVBQVMsWUFBMkI7SUFFaEQsTUFBTSxDQUFDLElBQUksT0FBTyxDQUFDLFNBQVMsQ0FBQyxZQUFZLENBQUMsQ0FBQztBQUMvQyxDQUFDLENBQUM7QUFDRixpQkFBUyxTQUFTLENBQUMiLCJmaWxlIjoidGFza2J1ZmZlci50YXNrY2hhaW4uanMiLCJzb3VyY2VzQ29udGVudCI6WyIvLy8gPHJlZmVyZW5jZSBwYXRoPVwiLi90eXBpbmdzL21haW4uZC50c1wiIC8+XG5pbXBvcnQgY2xhc3NlcyA9IHJlcXVpcmUoXCIuL3Rhc2tidWZmZXIuY2xhc3Nlc1wiKTtcbnZhciB0YXNrQ2hhaW4gPSBmdW5jdGlvbih0YXNrQXJyYXlBcmc6Y2xhc3Nlcy5UYXNrW10pe1xuXG4gICAgcmV0dXJuIG5ldyBjbGFzc2VzLlRhc2tDaGFpbih0YXNrQXJyYXlBcmcpO1xufTtcbmV4cG9ydCA9IHRhc2tDaGFpbjtcbiJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==

View File

@ -1,6 +1,6 @@
{
"name": "taskbuffer",
"version": "0.0.1",
"version": "0.1.0",
"description": "manage triggers and execution of tasks with promises",
"main": "dist/index.js",
"scripts": {
@ -23,11 +23,14 @@
},
"homepage": "https://github.com/pushrocks/taskbuffer#readme",
"dependencies": {
"beautylog": "^2.1.1",
"npmts": "^3.0.2",
"q": "^1.4.1"
"beautylog": "^5.0.0",
"lodash": "^4.12.0",
"projectinfo": "1.0.1",
"q": "^1.4.1",
"rx": "^4.1.0"
},
"devDependencies": {
"should": "^8.2.2"
"should": "^8.3.1",
"npmts": "^5.1.5"
}
}

0
test/test.d.ts vendored Normal file
View File

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,IAAI,UAAU,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC7C,QAAQ,CAAC,iBAAiB,EAAC;IACvB,QAAQ,CAAC,OAAO,EAAC;QACb,EAAE,CAAC,0BAA0B,EAAC;YAC1B,IAAI,MAAM,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;QACnC,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,IAAI,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAC1C,IAAI,OAAO,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AACpD,IAAI,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC/B,QAAQ,CAAC,YAAY,EAAC;IAClB,QAAQ,CAAC,SAAS,EAAC;QACf,IAAI,QAAQ,CAAC;QACb,EAAE,CAAC,0CAA0C,EAAC;YAC1C,QAAQ,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qCAAqC,EAAC;YACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,uBAAuB,EAAC;YACvB,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA,CAAC;gBAChB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;YACjD,CAAC;QACL,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,sDAAsD,EAAC;YACtD,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC3C,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;QACvC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

View File

@ -1,9 +1,84 @@
/// <reference path="../ts/typings/main.d.ts" />
var taskbuffer = require("../dist/index.js");
describe("taskbuffer.task",function(){
describe(".task",function(){
it("should return a new task",function(){
var myTask = taskbuffer.task();
})
import taskbuffer = require("../dist/index");
let should = require("should");
let plugins = {
q: require("q")
}
// setup some testData to work with
let testTask:taskbuffer.Task;
let testTaskFunction = function(){
let done = plugins.q.defer();
console.log("main function executed!")
done.resolve();
return done.promise;
}
let testPreTask = new taskbuffer.Task({
taskFunction:function(){
console.log("preTask executed");
},
preTask:testTask
});
describe("taskbuffer",function(){
describe(".Task",function(){
it("new Task() should return a new task",function(){
testTask = new taskbuffer.Task({taskFunction:testTaskFunction,preTask:testPreTask});
});
it("testTask should be and instance of Task",function(){
testTask.should.be.instanceof(taskbuffer.Task);
});
it("testTask.idle is true",function(){
if (!testTask.idle){
throw new Error("testTask.idle is not true");
}
});
it("testTask.running is type boolean and initially false",function(){
testTask.running.should.be.type("boolean");
testTask.running.should.be.false();
});
it("testTask.trigger() should return Promise",function(){
testTask.trigger().should.be.Promise();
});
it("testTask.trigger() returned Promise should be fullfilled",function(done){
testTask.trigger()
.then(done);
});
it("should run a task without pre and afterTask",function(done){
let localTestTask = new taskbuffer.Task({taskFunction:testTaskFunction});
localTestTask.trigger().then(done);
});
});
describe("Taskchain",function(){
let testTaskchain;
let testTaskArray = [
new taskbuffer.Task({
name:"task1",
taskFunction:function(){
let done = plugins.q.defer();
console.log("Task1 run");
done.resolve();
return done.promise;
}
}),
new taskbuffer.Task({
name:"task2",
taskFunction: function(){
let done = plugins.q.defer();
console.log("Task2 run");
done.resolve();
return done.promise;
}
}),
];
it("should run tasks in sequence",function(done){
testTaskchain = new taskbuffer.Taskchain({
name:"Taskchain1",
taskArray:testTaskArray
});
testTaskchain.trigger().then(done);
});
});
});

View File

@ -1,11 +1,5 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./taskbuffer.plugins");
import classes = require("./taskbuffer.classes");
import task = require("./taskbuffer.task");
import taskchain = require("./taskbuffer.taskchain");
export * from "./taskbuffer.classes";
var taskbuffer = {
task: task
};
export = taskbuffer;
// import for naming only
import "./taskbuffer.classes.helpers"

View File

@ -0,0 +1,97 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./taskbuffer.plugins");
import {Task} from "./taskbuffer.classes"
export let emptyTaskFunction = function(){
let done = plugins.Q.defer();
done.resolve();
return done.promise;
};
export let isTask = function(taskArg):boolean{
if(
taskArg instanceof Task
&& typeof taskArg.task === "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 = function(taskArg:Task,optionsArg:{touchedTasksArray:Task[]} = {touchedTasksArray:[]}){
let done = plugins.Q.defer();
updateTaskStatus(taskArg,"running");
done.promise.then(function(){updateTaskStatus(taskArg,"idle")})
let localDeferred = plugins.Q.defer();
let touchedTasksArray:Task[];
if(optionsArg.touchedTasksArray){
touchedTasksArray = optionsArg.touchedTasksArray;
} else {
touchedTasksArray = [];
}
touchedTasksArray.push(taskArg);
localDeferred.promise
.then(() =>{
if(taskArg.preTask && !isTaskTouched(taskArg.preTask,touchedTasksArray)){
return runTask(taskArg.preTask,{touchedTasksArray:touchedTasksArray})
} else {
let done2 = plugins.Q.defer();
done2.resolve();
return done2.promise;
}
})
.then(() => {
return taskArg.task();
})
.then(() => {
if(taskArg.afterTask && !isTaskTouched(taskArg.afterTask,touchedTasksArray)){
return runTask(taskArg.afterTask,{touchedTasksArray:touchedTasksArray})
} else {
let done2 = plugins.Q.defer();
done2.resolve();
return done2.promise;
}
})
.then(() => {
done.resolve();
});
localDeferred.resolve();
return done.promise;
};
export let runBufferedTask = (taskArg:Task) => {
let recursiveBufferRunner = () => {
if(taskArg.bufferCounter > 0){
taskArg.bufferCounter--;
runTask(taskArg)
.then(recursiveBufferRunner);
}
}
}
export let updateTaskStatus = (taskArg,statusArg:string) => {
switch (statusArg) {
case "running":
taskArg.running = true;
taskArg.idle = false;
break;
case "idle":
taskArg.running = false;
taskArg.idle = true;
break;
default:
throw new Error("status not recognised");
}
}

View File

@ -0,0 +1,72 @@
/// <reference path="./typings/main.d.ts" />
import * as plugins from "./taskbuffer.plugins"
import * as helpers from "./taskbuffer.classes.helpers"
export class Task {
name:string;
task:any;
running:boolean;
idle:boolean;
buffered:boolean;
bufferCounter:number;
bufferMax:number;
private _counterTriggerAbsolute:number;
private _state:string;
preTask:Task;
afterTask:Task;
constructor(optionsArg:{
taskFunction:any,
preTask?:Task,
afterTask?:Task,
buffered?:boolean,
bufferMax?:number,
name?:string
}){
if (!optionsArg){optionsArg = {taskFunction:function(){}}}
var options = optionsArg;
this.task = optionsArg.taskFunction;
this.preTask = options.preTask;
this.afterTask = options.afterTask;
this.running = false;
this.idle = true;
this.buffered = options.buffered;
this.bufferMax = options.bufferMax;
this.name = options.name;
}
trigger(){
let done = plugins.Q.defer();
if(this.buffered) {
this.triggerBuffered()
.then(done.resolve);
}
else {
this.triggerUnBuffered()
.then(done.resolve);
};
return done.promise;
};
triggerUnBuffered(){
return helpers.runTask(this);
}
triggerBuffered(){
var done = plugins.Q.defer();
if(!(this.bufferCounter >= this.bufferMax)){
this.bufferCounter++
}
helpers.runBufferedTask(this);
return done.promise;
}
get state():string {
return this._state;
}
set state(stateArg:string){
if (stateArg == "locked"){
this._state = "locked";
} else {
plugins.beautylog.error("state type " + stateArg.blue + " could not be set");
}
}
}

View File

@ -0,0 +1,68 @@
/// <reference path="./typings/main.d.ts" />
import * as plugins from "./taskbuffer.plugins";
import {Task} from "./taskbuffer.classes";
import helpers = require("./taskbuffer.classes.helpers");
export class Taskchain extends Task {
taskArray:Task[];
private _oraObject;
constructor(optionsArg:{
name?:string,
log?:boolean,
taskArray:Task[]
}){
let options = plugins.lodash.assign(
{
name:"unnamed Task",
log:false
},
optionsArg,
{
taskFunction: () => { // this is the function that gets executed when TaskChain is triggered
console.log("running taskchain function");
let done = plugins.Q.defer(); // this is the starting Deferred object
let taskCounter = 0;
let iterateTasks = () => {
if(typeof this.taskArray[taskCounter] != "undefined"){
this.taskArray[taskCounter].trigger()
.then(()=>{
taskCounter++;
iterateTasks();
});
} else {
done.resolve();
}
};
iterateTasks();
return done.promise;
}
}
);
super(options);
this.taskArray = optionsArg.taskArray;
this._oraObject = new plugins.beautylog.Ora("Taskchain idle","blue");
}
addTask(taskArg:Task){
this.taskArray.push(taskArg);
};
removeTask(taskArg:Task){
//TODO
};
shiftTask(){
};
trigger(){
this._oraObject.start(this.name + " running...");
return helpers.runTask(this);
}
};
let myTask = new Taskchain(
{
taskArray: [
new Task({
taskFunction:function(){}
})
]
}
);

View File

View File

@ -1,43 +1,2 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./taskbuffer.plugins");
export class Task {
task:any;
idle:boolean;
buffered:boolean;
bufferedForced:boolean;
running:boolean;
private _state:string;
preTask:Task;
afterTask:Task;
constructor(taskArg,optionsArg?:{preTask?:Task,afterTask?:Task}){
this.task = taskArg;
}
trigger(){
this.preTask.task()
.then(this.task)
.then(this.afterTask.task);
};
triggerBuffered(){
var done = plugins.Q.defer();
}
get state():string {
return this._state;
}
set state(stateArg:string){
if (stateArg == "locked"){
this._state = "locked";
} else {
plugins.beautylog.error("state type" );
}
}
}
export class TaskChain extends Task {
constructor(taskArrayArg:Task[]){
super({
task:function(){}
});
}
}
export * from "./taskbuffer.classes.task"
export * from "./taskbuffer.classes.taskchain"

View File

@ -1,6 +1,4 @@
/// <reference path="./typings/main.d.ts" />
var plugins = {
beautylog: require("beautylog"),
Q: require("q")
};
export = plugins;
export import beautylog = require("beautylog");
export let Q = require("q");
export let lodash= require("lodash");

View File

@ -1 +0,0 @@
/// <reference path="./typings/main.d.ts" />

View File

@ -1,7 +0,0 @@
/// <reference path="./typings/main.d.ts" />
import classes = require("./taskbuffer.classes");
var task = function(taskArg,options?){
var task = taskArg
return new classes.Task(task,options);
};
export = task;

View File

@ -1,7 +0,0 @@
/// <reference path="./typings/main.d.ts" />
import classes = require("./taskbuffer.classes");
var taskChain = function(taskArrayArg:classes.Task[]){
return new classes.TaskChain(taskArrayArg);
};
export = taskChain;

View File

@ -1,7 +1,8 @@
{
"ambientDependencies": {
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts",
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts",
"mocha": "github:Bartvds/tsd-deftools/typings/DefinitelyTyped/mocha/mocha.d.ts",
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts"
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts",
"should": "registry:dt/should#8.1.1+20160316155526"
}
}