2016-05-04 01:44:54 +00:00
|
|
|
/// <reference path="./typings/main.d.ts" />
|
|
|
|
import * as plugins from "./taskbuffer.plugins"
|
|
|
|
import * as helpers from "./taskbuffer.classes.helpers"
|
|
|
|
|
|
|
|
export class Task {
|
2016-05-04 02:28:50 +00:00
|
|
|
task:any;
|
2016-05-04 01:44:54 +00:00
|
|
|
idle:boolean;
|
|
|
|
running:boolean;
|
|
|
|
buffered:boolean;
|
2016-05-04 03:11:08 +00:00
|
|
|
bufferCounter:number;
|
|
|
|
bufferMax:number;
|
|
|
|
private _counterTriggerAbsolute:number;
|
2016-05-04 01:44:54 +00:00
|
|
|
private _state:string;
|
|
|
|
preTask:Task;
|
|
|
|
afterTask:Task;
|
|
|
|
|
2016-05-05 16:06:04 +00:00
|
|
|
constructor(optionsArg:{taskFunction:any,preTask?:Task,afterTask?:Task, buffered?:boolean}){
|
|
|
|
if (!optionsArg){optionsArg = {taskFunction:function(){}}}
|
2016-05-04 01:44:54 +00:00
|
|
|
var options = optionsArg;
|
2016-05-05 16:06:04 +00:00
|
|
|
this.task = optionsArg.taskFunction;
|
2016-05-04 01:44:54 +00:00
|
|
|
this.preTask = options.preTask;
|
|
|
|
this.afterTask = options.afterTask;
|
|
|
|
this.idle = true;
|
|
|
|
this.running = false;
|
2016-05-05 16:06:04 +00:00
|
|
|
this.buffered = options.buffered;
|
2016-05-04 01:44:54 +00:00
|
|
|
}
|
|
|
|
trigger(){
|
2016-05-04 02:17:59 +00:00
|
|
|
let done = plugins.Q.defer();
|
2016-05-05 16:06:04 +00:00
|
|
|
return helpers.runTask(this)
|
2016-05-04 01:44:54 +00:00
|
|
|
};
|
|
|
|
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" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|