2016-05-04 00:49:43 +00:00
|
|
|
/// <reference path="./typings/main.d.ts" />
|
|
|
|
import plugins = require("./taskbuffer.plugins");
|
2016-05-05 16:36:31 +00:00
|
|
|
import {Task} from "./taskbuffer.classes"
|
2016-05-04 00:49:43 +00:00
|
|
|
|
2016-05-05 16:36:31 +00:00
|
|
|
export let emptyTaskFunction = function(){
|
2016-05-05 16:06:04 +00:00
|
|
|
let done = plugins.Q.defer();
|
2016-05-04 00:49:43 +00:00
|
|
|
done.resolve();
|
|
|
|
return done.promise;
|
|
|
|
};
|
|
|
|
|
2016-05-05 16:36:31 +00:00
|
|
|
export let isTask = function(taskArg):boolean{
|
2016-05-04 00:49:43 +00:00
|
|
|
if(
|
2016-05-05 16:36:31 +00:00
|
|
|
taskArg instanceof Task
|
2016-05-04 00:49:43 +00:00
|
|
|
&& typeof taskArg.task === "function"
|
|
|
|
){
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-05 16:06:04 +00:00
|
|
|
|
2016-05-05 16:36:31 +00:00
|
|
|
export let isTaskTouched = (task:Task, touchedTasksArray:Task[]):boolean => {
|
2016-05-05 16:06:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-05 16:36:31 +00:00
|
|
|
export let runTask = function(taskArg:Task,optionsArg?:{touchedTasksArray:Task[]}){
|
2016-05-05 16:06:04 +00:00
|
|
|
let done = plugins.Q.defer();
|
|
|
|
let localDeferred = plugins.Q.defer();
|
2016-05-05 16:36:31 +00:00
|
|
|
let touchedTasksArray:Task[];
|
2016-05-05 16:06:04 +00:00
|
|
|
if(optionsArg.touchedTasksArray){
|
|
|
|
touchedTasksArray = optionsArg.touchedTasksArray;
|
|
|
|
} else {
|
|
|
|
touchedTasksArray = [];
|
2016-05-04 00:49:43 +00:00
|
|
|
}
|
2016-05-05 16:06:04 +00:00
|
|
|
touchedTasksArray.push(taskArg);
|
|
|
|
localDeferred.promise
|
|
|
|
.then(() =>{
|
|
|
|
if(taskArg.preTask && !isTaskTouched(taskArg.preTask,touchedTasksArray)){
|
|
|
|
return runTask(taskArg.preTask,{touchedTasksArray:touchedTasksArray})
|
|
|
|
} else {
|
|
|
|
let done2 = plugins.Q.resolve();
|
|
|
|
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.resolve();
|
|
|
|
done2.resolve();
|
|
|
|
return done2.promise;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
done.resolve();
|
|
|
|
})
|
|
|
|
|
2016-05-04 00:49:43 +00:00
|
|
|
return done.promise;
|
2016-05-05 17:21:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let runBufferedTask = (taskArg:Task) => {
|
|
|
|
|
|
|
|
}
|