now has working task class

This commit is contained in:
LosslessBot 2016-05-06 02:05:45 +02:00
parent 55ddbece13
commit ee56b6f655
9 changed files with 155 additions and 40 deletions

View File

@ -1,8 +1,9 @@
import { Task } from "./taskbuffer.classes";
export declare let emptyTaskFunction: () => any;
export declare let isTask: (taskArg: any) => boolean;
export declare let isTaskTouched: (task: Task, touchedTasksArray: Task[]) => 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;

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
export declare class Task {
task: any;
idle: boolean;
running: boolean;
idle: boolean;
buffered: boolean;
bufferCounter: number;
bufferMax: number;
@ -16,7 +16,7 @@ export declare class Task {
buffered?: boolean;
bufferMax?: number;
});
trigger(): void;
trigger(): any;
triggerUnBuffered(): any;
triggerBuffered(): any;
state: string;

View File

@ -11,20 +11,23 @@ var Task = (function () {
this.task = optionsArg.taskFunction;
this.preTask = options.preTask;
this.afterTask = options.afterTask;
this.idle = true;
this.running = false;
this.idle = true;
this.buffered = options.buffered;
this.bufferMax = options.bufferMax;
}
Task.prototype.trigger = function () {
var done = plugins.Q.defer();
if (this.buffered) {
this.triggerBuffered();
this.triggerBuffered()
.then(done.resolve);
}
else {
this.triggerUnBuffered();
this.triggerUnBuffered()
.then(done.resolve);
}
;
return done.promise;
};
;
Task.prototype.triggerUnBuffered = function () {
@ -47,7 +50,7 @@ var Task = (function () {
this._state = "locked";
}
else {
plugins.beautylog.error("state type");
plugins.beautylog.error("state type " + stateArg.blue + " could not be set");
}
},
enumerable: true,
@ -57,4 +60,4 @@ var Task = (function () {
}());
exports.Task = Task;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIuY2xhc3Nlcy50Y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ckJ1ZmZlcmVkKCl7XG4gICAgICAgIHZhciBkb25lID0gcGx1Z2lucy5RLmRlZmVyKCk7XG4gICAgICAgIGlmKCEodGhpcy5idWZmZXJDb3VudGVyID49IHRoaXMuYnVmZmVyTWF4KSl7XG4gICAgICAgICAgICB0aGlzLmJ1ZmZlckNvdW50ZXIrK1xuICAgICAgICB9XG4gICAgICAgIGhlbHBlcnMucnVuQnVmZmVyZWRUYXNrKHRoaXMpO1xuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xuICAgIH1cblxuICAgIGdldCBzdGF0ZSgpOnN0cmluZyB7XG4gICAgICAgIHJldHVybiB0aGlzLl9zdGF0ZTtcbiAgICB9XG4gICAgc2V0IHN0YXRlKHN0YXRlQXJnOnN0cmluZyl7XG4gICAgICAgIGlmIChzdGF0ZUFyZyA9PSBcImxvY2tlZFwiKXtcbiAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gXCJsb2NrZWRcIjtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHBsdWdpbnMuYmVhdXR5bG9nLmVycm9yKFwic3RhdGUgdHlwZSBcIiArIHN0YXRlQXJnLmJsdWUgKyBcIiBjb3VsZCBub3QgYmUgc2V0XCIpO1xuICAgICAgICB9XG4gICAgfVxufSJdfQ==

View File

@ -2,11 +2,22 @@
/// <reference path="../ts/typings/main.d.ts" />
var taskbuffer = require("../dist/index");
var should = require("should");
var plugins = {
q: require("q")
};
//setup some testData to work with
var testTask;
var testTaskFunction = function () {
var done = plugins.q.defer();
console.log("main function executed!");
done.resolve();
return done.promise;
};
var testPreTask = new taskbuffer.Task({ taskFunction: function () { console.log("preTask executed"); }, preTask: testTask });
describe("taskbuffer", function () {
describe(".task()", function () {
var testTask;
it("should return a new task to var testTask", function () {
testTask = new taskbuffer.Task({ taskFunction: 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);
@ -20,7 +31,14 @@ describe("taskbuffer", 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);
});
});
});
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLGdEQUFnRDtBQUNoRCxJQUFPLFVBQVUsV0FBVyxlQUFlLENBQUMsQ0FBQztBQUM3QyxJQUFJLE1BQU0sR0FBRyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUM7QUFDL0IsUUFBUSxDQUFDLFlBQVksRUFBQztJQUNsQixRQUFRLENBQUMsU0FBUyxFQUFDO1FBQ2YsSUFBSSxRQUFRLENBQUM7UUFDYixFQUFFLENBQUMsMENBQTBDLEVBQUM7WUFDMUMsUUFBUSxHQUFHLElBQUksVUFBVSxDQUFDLElBQUksQ0FBQyxFQUFDLFlBQVksRUFBQyxjQUFXLENBQUMsRUFBQyxDQUFDLENBQUM7UUFDaEUsQ0FBQyxDQUFDLENBQUM7UUFFSCxFQUFFLENBQUMseUNBQXlDLEVBQUM7WUFDekMsUUFBUSxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFVBQVUsQ0FBQyxJQUFJLENBQUMsQ0FBQztRQUNuRCxDQUFDLENBQUMsQ0FBQztRQUNILEVBQUUsQ0FBQyx1QkFBdUIsRUFBQztZQUN2QixFQUFFLENBQUMsQ0FBQyxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsQ0FBQSxDQUFDO2dCQUNoQixNQUFNLElBQUksS0FBSyxDQUFDLDJCQUEyQixDQUFDLENBQUM7WUFDakQsQ0FBQztRQUNMLENBQUMsQ0FBQyxDQUFDO1FBQ0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KFwiYm9vbGVhblwiKTtcbiAgICAgICAgICAgIHRlc3RUYXNrLnJ1bm5pbmcuc2hvdWxkLmJlLmZhbHNlKCk7XG4gICAgICAgIH0pO1xuICAgICAgICBpdChcInRlc3RUYXNrLnRyaWdnZXIoKSBzaG91bGQgcmV0dXJuIFByb21pc2VcIixmdW5jdGlvbigpe1xuICAgICAgICAgICAgdGVzdFRhc2sudHJpZ2dlcigpLnNob3VsZC5iZS5Qcm9taXNlKCk7XG4gICAgICAgIH0pO1xuICAgICAgICBpdChcInRlc3RUYXNrLnRyaWdnZXIoKSByZXR1cm5lZCBQcm9taXNlIHNob3VsZCBiZSBmdWxsZmlsbGVkXCIsZnVuY3Rpb24oZG9uZSl7XG4gICAgICAgICAgICB0ZXN0VGFzay50cmlnZ2VyKClcbiAgICAgICAgICAgICAgICAudGhlbihkb25lKTtcbiAgICAgICAgfSlcbiAgICB9KTtcbn0pOyJdfQ==

View File

@ -1,13 +1,30 @@
/// <reference path="../ts/typings/main.d.ts" />
import taskbuffer = require("../dist/index");
let should = require("should");
describe("taskbuffer",function(){
describe(".task()",function(){
var testTask;
it("should return a new task to var testTask",function(){
testTask = new taskbuffer.Task({taskFunction:function(){}});
});
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);
});
@ -15,10 +32,18 @@ describe("taskbuffer",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);
})
});
});

View File

@ -20,12 +20,20 @@ export let isTask = function(taskArg):boolean{
};
export let isTaskTouched = (task:Task, touchedTasksArray:Task[]):boolean => {
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[]}){
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){
@ -39,7 +47,7 @@ export let runTask = function(taskArg:Task,optionsArg?:{touchedTasksArray:Task[]
if(taskArg.preTask && !isTaskTouched(taskArg.preTask,touchedTasksArray)){
return runTask(taskArg.preTask,{touchedTasksArray:touchedTasksArray})
} else {
let done2 = plugins.Q.resolve();
let done2 = plugins.Q.defer();
done2.resolve();
return done2.promise;
}
@ -51,18 +59,39 @@ export let runTask = function(taskArg:Task,optionsArg?:{touchedTasksArray:Task[]
if(taskArg.afterTask && !isTaskTouched(taskArg.afterTask,touchedTasksArray)){
return runTask(taskArg.afterTask,{touchedTasksArray:touchedTasksArray})
} else {
let done2 = plugins.Q.resolve();
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

@ -5,8 +5,8 @@ import * as helpers from "./taskbuffer.classes.helpers"
export class Task {
task:any;
idle:boolean;
running:boolean;
idle:boolean;
buffered:boolean;
bufferCounter:number;
bufferMax:number;
@ -21,16 +21,23 @@ export class Task {
this.task = optionsArg.taskFunction;
this.preTask = options.preTask;
this.afterTask = options.afterTask;
this.idle = true;
this.running = false;
this.idle = true;
this.buffered = options.buffered;
this.bufferMax = options.bufferMax;
}
trigger(){
let done = plugins.Q.defer();
if(this.buffered) {this.triggerBuffered()}
else{this.triggerUnBuffered()};
if(this.buffered) {
this.triggerBuffered()
.then(done.resolve);
}
else {
this.triggerUnBuffered()
.then(done.resolve);
};
return done.promise;
};
triggerUnBuffered(){
return helpers.runTask(this);
@ -51,7 +58,7 @@ export class Task {
if (stateArg == "locked"){
this._state = "locked";
} else {
plugins.beautylog.error("state type" );
plugins.beautylog.error("state type " + stateArg.blue + " could not be set");
}
}
}

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"
}
}