taskbuffer/ts/taskbuffer.classes.helpers.ts

68 lines
1.9 KiB
TypeScript
Raw Normal View History

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