values now flow correctly between tasks
This commit is contained in:
parent
5dca9a9460
commit
76c57451b3
9
dist/taskbuffer.classes.helpers.d.ts
vendored
9
dist/taskbuffer.classes.helpers.d.ts
vendored
@ -4,8 +4,9 @@ import { Task, ITaskFunction } from "./taskbuffer.classes.task";
|
|||||||
export declare let emptyTaskFunction: ITaskFunction;
|
export declare let emptyTaskFunction: ITaskFunction;
|
||||||
export declare let isTask: (taskArg: any) => boolean;
|
export declare let isTask: (taskArg: any) => boolean;
|
||||||
export declare let isTaskTouched: (taskArg: Task, touchedTasksArray: Task[]) => boolean;
|
export declare let isTaskTouched: (taskArg: Task, touchedTasksArray: Task[]) => boolean;
|
||||||
export declare let runTask: (taskArg: Task, optionsArg?: {
|
export declare let runTask: (taskArg: Task, optionsArg: {
|
||||||
touchedTasksArray: Task[];
|
x?: any;
|
||||||
|
touchedTasksArray?: Task[];
|
||||||
}) => plugins.Q.Promise<{}>;
|
}) => plugins.Q.Promise<{}>;
|
||||||
export interface cycleObject {
|
export interface cycleObject {
|
||||||
cycleCounter: number;
|
cycleCounter: number;
|
||||||
@ -24,7 +25,7 @@ export declare class BufferRunner {
|
|||||||
bufferMax: number;
|
bufferMax: number;
|
||||||
running: boolean;
|
running: boolean;
|
||||||
constructor(taskArg: Task);
|
constructor(taskArg: Task);
|
||||||
private _run();
|
private _run(x);
|
||||||
setBufferMax(bufferMaxArg: number): void;
|
setBufferMax(bufferMaxArg: number): void;
|
||||||
trigger(): PromiseLike<any>;
|
trigger(x: any): PromiseLike<any>;
|
||||||
}
|
}
|
||||||
|
57
dist/taskbuffer.classes.helpers.js
vendored
57
dist/taskbuffer.classes.helpers.js
vendored
File diff suppressed because one or more lines are too long
12
dist/taskbuffer.classes.task.d.ts
vendored
12
dist/taskbuffer.classes.task.d.ts
vendored
@ -1,12 +1,10 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
import * as plugins from "./taskbuffer.plugins";
|
|
||||||
import * as helpers from "./taskbuffer.classes.helpers";
|
import * as helpers from "./taskbuffer.classes.helpers";
|
||||||
export interface ITaskFunction {
|
export interface ITaskFunction {
|
||||||
(): PromiseLike<any>;
|
(x?: any): PromiseLike<any>;
|
||||||
}
|
}
|
||||||
export declare class Task {
|
export declare class Task {
|
||||||
name: string;
|
name: string;
|
||||||
task: any;
|
taskFunction: ITaskFunction;
|
||||||
buffered: boolean;
|
buffered: boolean;
|
||||||
preTask: Task;
|
preTask: Task;
|
||||||
afterTask: Task;
|
afterTask: Task;
|
||||||
@ -26,14 +24,14 @@ export declare class Task {
|
|||||||
/**
|
/**
|
||||||
* trigger the task. Will trigger buffered if this.buffered is true
|
* trigger the task. Will trigger buffered if this.buffered is true
|
||||||
*/
|
*/
|
||||||
trigger(): plugins.Q.Promise<{}>;
|
trigger(x?: any): PromiseLike<any>;
|
||||||
/**
|
/**
|
||||||
* trigger task unbuffered.
|
* trigger task unbuffered.
|
||||||
*/
|
*/
|
||||||
triggerUnBuffered(): PromiseLike<any>;
|
triggerUnBuffered(x?: any): PromiseLike<any>;
|
||||||
/**
|
/**
|
||||||
* trigger task buffered.
|
* trigger task buffered.
|
||||||
*/
|
*/
|
||||||
triggerBuffered(): PromiseLike<any>;
|
triggerBuffered(x?: any): PromiseLike<any>;
|
||||||
state: string;
|
state: string;
|
||||||
}
|
}
|
||||||
|
22
dist/taskbuffer.classes.task.js
vendored
22
dist/taskbuffer.classes.task.js
vendored
@ -10,7 +10,7 @@ class Task {
|
|||||||
this.idle = true;
|
this.idle = true;
|
||||||
this._state = "ready";
|
this._state = "ready";
|
||||||
var options = optionsArg;
|
var options = optionsArg;
|
||||||
this.task = optionsArg.taskFunction;
|
this.taskFunction = optionsArg.taskFunction;
|
||||||
this.preTask = options.preTask;
|
this.preTask = options.preTask;
|
||||||
this.afterTask = options.afterTask;
|
this.afterTask = options.afterTask;
|
||||||
this.idle = !this.running;
|
this.idle = !this.running;
|
||||||
@ -21,31 +21,27 @@ class Task {
|
|||||||
/**
|
/**
|
||||||
* trigger the task. Will trigger buffered if this.buffered is true
|
* trigger the task. Will trigger buffered if this.buffered is true
|
||||||
*/
|
*/
|
||||||
trigger() {
|
trigger(x) {
|
||||||
let done = plugins.Q.defer();
|
|
||||||
if (this.buffered) {
|
if (this.buffered) {
|
||||||
this.triggerBuffered()
|
return this.triggerBuffered(x);
|
||||||
.then(done.resolve);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.triggerUnBuffered()
|
return this.triggerUnBuffered(x);
|
||||||
.then(done.resolve);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
return done.promise;
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
/**
|
/**
|
||||||
* trigger task unbuffered.
|
* trigger task unbuffered.
|
||||||
*/
|
*/
|
||||||
triggerUnBuffered() {
|
triggerUnBuffered(x) {
|
||||||
return helpers.runTask(this);
|
return helpers.runTask(this, { x: x });
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* trigger task buffered.
|
* trigger task buffered.
|
||||||
*/
|
*/
|
||||||
triggerBuffered() {
|
triggerBuffered(x) {
|
||||||
return this.bufferRunner.trigger();
|
return this.bufferRunner.trigger(x);
|
||||||
}
|
}
|
||||||
get state() {
|
get state() {
|
||||||
return this._state;
|
return this._state;
|
||||||
@ -60,4 +56,4 @@ class Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.Task = Task;
|
exports.Task = Task;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMudGFzay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sc0JBQ3pCLENBQUMsQ0FEOEM7QUFDL0MsTUFBWSxPQUFPLFdBQU0sOEJBR3pCLENBQUMsQ0FIc0Q7QUFPdkQ7SUFj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buffer.classes.taskchain.d.ts
vendored
@ -3,12 +3,13 @@ export declare class Taskchain extends Task {
|
|||||||
taskArray: Task[];
|
taskArray: Task[];
|
||||||
private _oraObject;
|
private _oraObject;
|
||||||
constructor(optionsArg: {
|
constructor(optionsArg: {
|
||||||
|
taskArray: Task[];
|
||||||
name?: string;
|
name?: string;
|
||||||
log?: boolean;
|
log?: boolean;
|
||||||
taskArray: Task[];
|
buffered?: boolean;
|
||||||
|
bufferMax?: number;
|
||||||
});
|
});
|
||||||
addTask(taskArg: Task): void;
|
addTask(taskArg: Task): void;
|
||||||
removeTask(taskArg: Task): void;
|
removeTask(taskArg: Task): void;
|
||||||
shiftTask(): void;
|
shiftTask(): void;
|
||||||
trigger(): any;
|
|
||||||
}
|
}
|
||||||
|
23
dist/taskbuffer.classes.taskchain.js
vendored
23
dist/taskbuffer.classes.taskchain.js
vendored
@ -1,32 +1,31 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const plugins = require("./taskbuffer.plugins");
|
const plugins = require("./taskbuffer.plugins");
|
||||||
const taskbuffer_classes_task_1 = require("./taskbuffer.classes.task");
|
const taskbuffer_classes_task_1 = require("./taskbuffer.classes.task");
|
||||||
const helpers = require("./taskbuffer.classes.helpers");
|
|
||||||
class Taskchain extends taskbuffer_classes_task_1.Task {
|
class Taskchain extends taskbuffer_classes_task_1.Task {
|
||||||
constructor(optionsArg) {
|
constructor(optionsArg) {
|
||||||
let options = plugins.lodash.merge({
|
let options = plugins.lodash.merge({
|
||||||
name: "unnamed Taskchain",
|
name: "unnamed Taskchain",
|
||||||
log: false
|
log: false
|
||||||
}, optionsArg, {
|
}, optionsArg, {
|
||||||
taskFunction: () => {
|
taskFunction: (x) => {
|
||||||
let done = plugins.Q.defer(); // this is the starting Deferred object
|
let done = plugins.Q.defer(); // this is the starting Deferred object
|
||||||
let taskCounter = 0;
|
let taskCounter = 0; // counter for iterating async over the taskArray
|
||||||
let iterateTasks = () => {
|
let iterateTasks = (x) => {
|
||||||
if (typeof this.taskArray[taskCounter] != "undefined") {
|
if (typeof this.taskArray[taskCounter] != "undefined") {
|
||||||
this._oraObject.text(this.name + " running: Task" + this.taskArray[taskCounter].name);
|
this._oraObject.text(this.name + " running: Task" + this.taskArray[taskCounter].name);
|
||||||
this.taskArray[taskCounter].trigger()
|
this.taskArray[taskCounter].trigger(x)
|
||||||
.then(() => {
|
.then((x) => {
|
||||||
plugins.beautylog.ok(this.taskArray[taskCounter].name);
|
plugins.beautylog.ok(this.taskArray[taskCounter].name);
|
||||||
taskCounter++;
|
taskCounter++;
|
||||||
iterateTasks();
|
iterateTasks(x);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this._oraObject.endOk("Taskchain \"" + this.name + "\" completed successfully");
|
this._oraObject.endOk("Taskchain \"" + this.name + "\" completed successfully");
|
||||||
done.resolve();
|
done.resolve(x);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
iterateTasks();
|
iterateTasks(x);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -49,11 +48,7 @@ class Taskchain extends taskbuffer_classes_task_1.Task {
|
|||||||
shiftTask() {
|
shiftTask() {
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
trigger() {
|
|
||||||
this._oraObject.start(this.name + " running...");
|
|
||||||
return helpers.runTask(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exports.Taskchain = Taskchain;
|
exports.Taskchain = Taskchain;
|
||||||
;
|
;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2tjaGFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3Rhc2tidWZmZXIuY2xhc3Nlcy50YXNrY2hhaW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQ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LFVBQVUsQ0FBQyxHQUFHLEtBQUssSUFBSSxDQUFDLENBQUEsQ0FBQztZQUN4QixJQUFJLENBQUMsVUFBVSxDQUFDLEtBQUssRUFBRSxDQUFDO1FBQzVCLENBQUM7UUFBQSxDQUFDO0lBQ04sQ0FBQztJQUNELE9BQU8sQ0FBQyxPQUFZO1FBQ2hCLElBQUksQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQ2pDLENBQUM7O0lBQ0QsVUFBVSxDQUFDLE9BQVk7UUFDbkIsTUFBTTtJQUNWLENBQUM7O0lBQ0QsU0FBUztJQUVULENBQUM7O0FBQ0wsQ0FBQztBQXZEWSxpQkFBUyxZQXVEckIsQ0FBQTtBQUFBLENBQUMifQ==
|
46
test/test.js
46
test/test.js
File diff suppressed because one or more lines are too long
44
test/test.ts
44
test/test.ts
@ -1,6 +1,6 @@
|
|||||||
import "typings-test";
|
import "typings-test";
|
||||||
import taskbuffer = require("../dist/index");
|
import taskbuffer = require("../dist/index");
|
||||||
let should = require("should");
|
import should = require("should");
|
||||||
import q = require("q")
|
import q = require("q")
|
||||||
|
|
||||||
// setup some testData to work with
|
// setup some testData to work with
|
||||||
@ -156,5 +156,47 @@ describe("taskbuffer", function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
});
|
||||||
|
describe("some flowtests",function(){
|
||||||
|
let flowTask1 = new taskbuffer.Task({
|
||||||
|
taskFunction: (x:number) => {
|
||||||
|
let done = q.defer();
|
||||||
|
console.log("flowTask1");
|
||||||
|
console.log(x);
|
||||||
|
done.resolve(x);
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let flowTask2 = new taskbuffer.Task({
|
||||||
|
taskFunction: (x:number) => {
|
||||||
|
let done = q.defer();
|
||||||
|
console.log("flowTask2");
|
||||||
|
console.log(x);
|
||||||
|
done.resolve(x);
|
||||||
|
return done.promise;
|
||||||
|
},
|
||||||
|
preTask:flowTask1
|
||||||
|
});
|
||||||
|
let flowTask3 = new taskbuffer.Taskchain({
|
||||||
|
taskArray:[flowTask1,flowTask2];
|
||||||
|
});
|
||||||
|
it("should let a value flow through a task",function(done){
|
||||||
|
flowTask1.trigger(12).then((x) => {
|
||||||
|
should.equal(x,12);
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
|
it("should let a values flow between tasks",function(done){
|
||||||
|
flowTask2.trigger(12).then((x) => {
|
||||||
|
should.equal(x,12);
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
|
it("should let a values flow between tasks in Taskchain",function(done){
|
||||||
|
flowTask3.trigger(12).then((x) => {
|
||||||
|
should.equal(x,12);
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
});
|
});
|
@ -1,7 +1,7 @@
|
|||||||
import plugins = require("./taskbuffer.plugins");
|
import plugins = require("./taskbuffer.plugins");
|
||||||
import { Task, ITaskFunction } from "./taskbuffer.classes.task";
|
import { Task, ITaskFunction } from "./taskbuffer.classes.task";
|
||||||
|
|
||||||
export let emptyTaskFunction: ITaskFunction = function () {
|
export let emptyTaskFunction: ITaskFunction = function (x) {
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
done.resolve();
|
done.resolve();
|
||||||
return done.promise;
|
return done.promise;
|
||||||
@ -29,42 +29,49 @@ export let isTaskTouched = (taskArg: Task, touchedTasksArray: Task[]): boolean =
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export let runTask = function (taskArg: Task, optionsArg: { touchedTasksArray: Task[] } = { touchedTasksArray: [] }) {
|
export let runTask = function (taskArg: Task, optionsArg: {x?, touchedTasksArray?: Task[] }) {
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
|
|
||||||
|
// set running params
|
||||||
taskArg.running = true;
|
taskArg.running = true;
|
||||||
done.promise.then(function () { taskArg.running = false });
|
done.promise.then(function () { taskArg.running = false });
|
||||||
let localDeferred = plugins.Q.defer();
|
|
||||||
let touchedTasksArray: Task[];
|
// handle options
|
||||||
if (optionsArg.touchedTasksArray) {
|
let options = plugins.lodash.merge(
|
||||||
touchedTasksArray = optionsArg.touchedTasksArray;
|
{x:undefined,touchedTasksArray: []},
|
||||||
} else {
|
optionsArg
|
||||||
touchedTasksArray = [];
|
)
|
||||||
}
|
let x = options.x;
|
||||||
|
let touchedTasksArray: Task[] = options.touchedTasksArray;
|
||||||
|
|
||||||
touchedTasksArray.push(taskArg);
|
touchedTasksArray.push(taskArg);
|
||||||
|
|
||||||
|
// run the task cascade
|
||||||
|
let localDeferred = plugins.Q.defer();
|
||||||
localDeferred.promise
|
localDeferred.promise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (taskArg.preTask && !isTaskTouched(taskArg.preTask, touchedTasksArray)) {
|
if (taskArg.preTask && !isTaskTouched(taskArg.preTask, touchedTasksArray)) {
|
||||||
return runTask(taskArg.preTask, { touchedTasksArray: touchedTasksArray })
|
return runTask(taskArg.preTask, {x:x, touchedTasksArray: touchedTasksArray })
|
||||||
} else {
|
} else {
|
||||||
let done2 = plugins.Q.defer();
|
let done2 = plugins.Q.defer();
|
||||||
done2.resolve();
|
done2.resolve(x);
|
||||||
return done2.promise;
|
return done2.promise;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(x => {
|
||||||
return taskArg.task();
|
return taskArg.taskFunction(x);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(x => {
|
||||||
if (taskArg.afterTask && !isTaskTouched(taskArg.afterTask, touchedTasksArray)) {
|
if (taskArg.afterTask && !isTaskTouched(taskArg.afterTask, touchedTasksArray)) {
|
||||||
return runTask(taskArg.afterTask, { touchedTasksArray: touchedTasksArray })
|
return runTask(taskArg.afterTask, {x:x, touchedTasksArray: touchedTasksArray });
|
||||||
} else {
|
} else {
|
||||||
let done2 = plugins.Q.defer();
|
let done2 = plugins.Q.defer();
|
||||||
done2.resolve();
|
done2.resolve(x);
|
||||||
return done2.promise;
|
return done2.promise;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(x => {
|
||||||
done.resolve();
|
done.resolve(x);
|
||||||
});
|
});
|
||||||
localDeferred.resolve();
|
localDeferred.resolve();
|
||||||
return done.promise;
|
return done.promise;
|
||||||
@ -114,34 +121,34 @@ export class BufferRunner {
|
|||||||
constructor(taskArg: Task) {
|
constructor(taskArg: Task) {
|
||||||
this.task = taskArg;
|
this.task = taskArg;
|
||||||
};
|
};
|
||||||
private _run() {
|
private _run(x) {
|
||||||
let recursiveBufferRunner = () => {
|
let recursiveBufferRunner = (x) => {
|
||||||
if (this.bufferCounter >= 0) {
|
if (this.bufferCounter >= 0) {
|
||||||
this.running = true;
|
this.running = true;
|
||||||
this.task.running = true;
|
this.task.running = true;
|
||||||
runTask(this.task)
|
runTask(this.task,{x:x})
|
||||||
.then(() => {
|
.then((x) => {
|
||||||
this.bufferCounter--;
|
this.bufferCounter--;
|
||||||
this.task.cycleCounter.informOfCycle();
|
this.task.cycleCounter.informOfCycle();
|
||||||
recursiveBufferRunner();
|
recursiveBufferRunner(x);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.task.running = false;
|
this.task.running = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
recursiveBufferRunner();
|
recursiveBufferRunner(x);
|
||||||
};
|
};
|
||||||
setBufferMax(bufferMaxArg:number){
|
setBufferMax(bufferMaxArg:number){
|
||||||
this.bufferMax = bufferMaxArg;
|
this.bufferMax = bufferMaxArg;
|
||||||
};
|
};
|
||||||
trigger(): PromiseLike<any> {
|
trigger(x): PromiseLike<any> {
|
||||||
if(!(this.bufferCounter >= this.bufferMax)){
|
if(!(this.bufferCounter >= this.bufferMax)){
|
||||||
this.bufferCounter++
|
this.bufferCounter++
|
||||||
};
|
};
|
||||||
let returnPromise:PromiseLike<any> = this.task.cycleCounter.getPromiseForCycle(this.bufferCounter + 1);
|
let returnPromise:PromiseLike<any> = this.task.cycleCounter.getPromiseForCycle(this.bufferCounter + 1);
|
||||||
if(!this.running){
|
if(!this.running){
|
||||||
this._run();
|
this._run(x);
|
||||||
}
|
}
|
||||||
return returnPromise;
|
return returnPromise;
|
||||||
};
|
};
|
||||||
|
@ -3,12 +3,12 @@ import * as helpers from "./taskbuffer.classes.helpers"
|
|||||||
|
|
||||||
|
|
||||||
export interface ITaskFunction {
|
export interface ITaskFunction {
|
||||||
():PromiseLike<any>;
|
(x?:any):PromiseLike<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Task {
|
export class Task {
|
||||||
name:string;
|
name:string;
|
||||||
task:any;
|
taskFunction:ITaskFunction;
|
||||||
buffered:boolean;
|
buffered:boolean;
|
||||||
preTask:Task;
|
preTask:Task;
|
||||||
afterTask:Task;
|
afterTask:Task;
|
||||||
@ -29,7 +29,7 @@ export class Task {
|
|||||||
name?:string
|
name?:string
|
||||||
}){
|
}){
|
||||||
var options = optionsArg;
|
var options = optionsArg;
|
||||||
this.task = optionsArg.taskFunction;
|
this.taskFunction = optionsArg.taskFunction;
|
||||||
this.preTask = options.preTask;
|
this.preTask = options.preTask;
|
||||||
this.afterTask = options.afterTask;
|
this.afterTask = options.afterTask;
|
||||||
this.idle = !this.running;
|
this.idle = !this.running;
|
||||||
@ -41,31 +41,27 @@ export class Task {
|
|||||||
/**
|
/**
|
||||||
* trigger the task. Will trigger buffered if this.buffered is true
|
* trigger the task. Will trigger buffered if this.buffered is true
|
||||||
*/
|
*/
|
||||||
trigger(){
|
trigger(x?):PromiseLike<any> {
|
||||||
let done = plugins.Q.defer();
|
|
||||||
if(this.buffered) {
|
if(this.buffered) {
|
||||||
this.triggerBuffered()
|
return this.triggerBuffered(x)
|
||||||
.then(done.resolve);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.triggerUnBuffered()
|
return this.triggerUnBuffered(x);
|
||||||
.then(done.resolve);
|
|
||||||
};
|
};
|
||||||
return done.promise;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* trigger task unbuffered.
|
* trigger task unbuffered.
|
||||||
*/
|
*/
|
||||||
triggerUnBuffered():PromiseLike<any>{
|
triggerUnBuffered(x?):PromiseLike<any>{
|
||||||
return helpers.runTask(this);
|
return helpers.runTask(this,{x:x});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* trigger task buffered.
|
* trigger task buffered.
|
||||||
*/
|
*/
|
||||||
triggerBuffered():PromiseLike<any>{
|
triggerBuffered(x?):PromiseLike<any>{
|
||||||
return this.bufferRunner.trigger();
|
return this.bufferRunner.trigger(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
get state():string {
|
get state():string {
|
||||||
|
@ -6,9 +6,11 @@ export class Taskchain extends Task {
|
|||||||
taskArray:Task[];
|
taskArray:Task[];
|
||||||
private _oraObject:plugins.beautylog.Ora;
|
private _oraObject:plugins.beautylog.Ora;
|
||||||
constructor(optionsArg:{
|
constructor(optionsArg:{
|
||||||
|
taskArray:Task[],
|
||||||
name?:string,
|
name?:string,
|
||||||
log?:boolean,
|
log?:boolean,
|
||||||
taskArray:Task[]
|
buffered?:boolean,
|
||||||
|
bufferMax?:number
|
||||||
}){
|
}){
|
||||||
let options = plugins.lodash.merge(
|
let options = plugins.lodash.merge(
|
||||||
{
|
{
|
||||||
@ -17,24 +19,24 @@ export class Taskchain extends Task {
|
|||||||
},
|
},
|
||||||
optionsArg,
|
optionsArg,
|
||||||
{
|
{
|
||||||
taskFunction: () => { // this is the function that gets executed when TaskChain is triggered
|
taskFunction: (x:any) => { // this is the function that gets executed when TaskChain is triggered
|
||||||
let done = plugins.Q.defer(); // this is the starting Deferred object
|
let done = plugins.Q.defer(); // this is the starting Deferred object
|
||||||
let taskCounter = 0;
|
let taskCounter = 0; // counter for iterating async over the taskArray
|
||||||
let iterateTasks = () => {
|
let iterateTasks = (x) => {
|
||||||
if(typeof this.taskArray[taskCounter] != "undefined"){
|
if(typeof this.taskArray[taskCounter] != "undefined"){
|
||||||
this._oraObject.text(this.name + " running: Task" + this.taskArray[taskCounter].name);
|
this._oraObject.text(this.name + " running: Task" + this.taskArray[taskCounter].name);
|
||||||
this.taskArray[taskCounter].trigger()
|
this.taskArray[taskCounter].trigger(x)
|
||||||
.then(()=>{
|
.then((x)=>{
|
||||||
plugins.beautylog.ok(this.taskArray[taskCounter].name);
|
plugins.beautylog.ok(this.taskArray[taskCounter].name);
|
||||||
taskCounter++;
|
taskCounter++;
|
||||||
iterateTasks();
|
iterateTasks(x);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this._oraObject.endOk("Taskchain \"" + this.name + "\" completed successfully");
|
this._oraObject.endOk("Taskchain \"" + this.name + "\" completed successfully");
|
||||||
done.resolve();
|
done.resolve(x);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
iterateTasks();
|
iterateTasks(x);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,8 +57,4 @@ export class Taskchain extends Task {
|
|||||||
shiftTask(){
|
shiftTask(){
|
||||||
|
|
||||||
};
|
};
|
||||||
trigger(){
|
|
||||||
this._oraObject.start(this.name + " running...");
|
|
||||||
return helpers.runTask(this);
|
|
||||||
}
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user