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:11:22 +00:00
|
|
|
task:function;
|
2016-05-04 01:44:54 +00:00
|
|
|
idle:boolean;
|
|
|
|
running:boolean;
|
|
|
|
buffered:boolean;
|
|
|
|
private _counterBufferRelative;
|
|
|
|
private _counterTriggerAbsolute;
|
|
|
|
private _state:string;
|
|
|
|
preTask:Task;
|
|
|
|
afterTask:Task;
|
|
|
|
|
|
|
|
constructor(taskArg,optionsArg:{preTask?:Task,afterTask?:Task, buffered?:boolean} = {}){
|
|
|
|
var options = optionsArg;
|
|
|
|
this.task = taskArg;
|
|
|
|
this.preTask = options.preTask;
|
|
|
|
this.afterTask = options.afterTask;
|
|
|
|
this.idle = true;
|
|
|
|
this.running = false;
|
|
|
|
if (typeof options.buffered === "boolean"){
|
|
|
|
this.buffered = options.buffered;
|
|
|
|
} else {
|
|
|
|
this.buffered = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
trigger(){
|
2016-05-04 02:17:59 +00:00
|
|
|
let done = plugins.Q.defer();
|
2016-05-04 01:44:54 +00:00
|
|
|
helpers.runTask(this.preTask)
|
|
|
|
.then(function(){
|
|
|
|
|
|
|
|
})
|
|
|
|
.then(function(){
|
|
|
|
|
|
|
|
})
|
2016-05-04 02:17:59 +00:00
|
|
|
.then(function(){
|
|
|
|
done.resolve();
|
|
|
|
});
|
|
|
|
return done.promise;
|
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" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|