add some more buffer logic
This commit is contained in:
parent
569cb311c9
commit
5fd11ec9c0
@ -62,3 +62,7 @@ export let runTask = function(taskArg:Task,optionsArg?:{touchedTasksArray:Task[]
|
||||
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
export let runBufferedTask = (taskArg:Task) => {
|
||||
|
||||
}
|
@ -15,7 +15,7 @@ export class Task {
|
||||
preTask:Task;
|
||||
afterTask:Task;
|
||||
|
||||
constructor(optionsArg:{taskFunction:any,preTask?:Task,afterTask?:Task, buffered?:boolean}){
|
||||
constructor(optionsArg:{taskFunction:any,preTask?:Task,afterTask?:Task, buffered?:boolean, bufferMax?:number}){
|
||||
if (!optionsArg){optionsArg = {taskFunction:function(){}}}
|
||||
var options = optionsArg;
|
||||
this.task = optionsArg.taskFunction;
|
||||
@ -24,13 +24,24 @@ export class Task {
|
||||
this.idle = true;
|
||||
this.running = false;
|
||||
this.buffered = options.buffered;
|
||||
this.bufferMax = options.bufferMax;
|
||||
}
|
||||
|
||||
trigger(){
|
||||
let done = plugins.Q.defer();
|
||||
return helpers.runTask(this);
|
||||
if(this.buffered) {this.triggerBuffered()}
|
||||
else{this.triggerUnBuffered()};
|
||||
};
|
||||
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 {
|
||||
|
@ -1,12 +1,12 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import * as plugins from "./taskbuffer.plugins";
|
||||
import * as classes from "./taskbuffer.classes"
|
||||
import {Task} from "./taskbuffer.classes";
|
||||
import helpers = require("./taskbuffer.classes.helpers");
|
||||
|
||||
export class Taskchain extends classes.Task {
|
||||
taskArray:classes.Task[];
|
||||
export class Taskchain extends Task {
|
||||
taskArray:Task[];
|
||||
|
||||
constructor(taskArrayArg:classes.Task[]|classes.Task){
|
||||
constructor(taskArrayArg:Task[]|Task){
|
||||
super({
|
||||
taskFunction: () => { // this is the function that gets executed when TaskChain is triggered
|
||||
if(this.taskArray.length = 0) return; //make sure there is actually a Task available to execute
|
||||
@ -22,10 +22,10 @@ export class Taskchain extends classes.Task {
|
||||
}
|
||||
});
|
||||
}
|
||||
addTask(taskArg:classes.Task){
|
||||
addTask(taskArg:Task){
|
||||
this.taskArray.push(taskArg);
|
||||
};
|
||||
removeTask(taskArg:classes.Task){
|
||||
removeTask(taskArg:Task){
|
||||
//TODO
|
||||
};
|
||||
shiftTask(){
|
||||
@ -34,7 +34,7 @@ export class Taskchain extends classes.Task {
|
||||
};
|
||||
|
||||
let myTask = new Taskchain(
|
||||
new classes.Task({
|
||||
new Task({
|
||||
taskFunction:function(){}
|
||||
})
|
||||
);
|
Loading…
Reference in New Issue
Block a user