update from q to smartq
This commit is contained in:
@ -1,19 +1,16 @@
|
||||
import plugins = require("./taskbuffer.plugins");
|
||||
import { Task, ITaskFunction } from "./taskbuffer.classes.task";
|
||||
|
||||
import {Promise} from "q";
|
||||
export {Promise} from "q";
|
||||
|
||||
export let emptyTaskFunction: ITaskFunction = function (x) {
|
||||
let done = plugins.Q.defer();
|
||||
let done = plugins.q.defer();
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
export let isTask = function (taskArg): boolean {
|
||||
export let isTask = function (taskArg: Task): boolean {
|
||||
if (
|
||||
taskArg instanceof Task
|
||||
&& typeof taskArg.task === "function"
|
||||
&& typeof taskArg.taskFunction === "function"
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
@ -33,7 +30,7 @@ export let isTaskTouched = (taskArg: Task, touchedTasksArray: Task[]): boolean =
|
||||
}
|
||||
|
||||
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;
|
||||
@ -50,13 +47,13 @@ export let runTask = function (taskArg: Task, optionsArg: {x?, touchedTasksArray
|
||||
touchedTasksArray.push(taskArg);
|
||||
|
||||
// run the task cascade
|
||||
let localDeferred = plugins.Q.defer();
|
||||
let localDeferred = plugins.q.defer();
|
||||
localDeferred.promise
|
||||
.then(() => {
|
||||
if (taskArg.preTask && !isTaskTouched(taskArg.preTask, touchedTasksArray)) {
|
||||
return runTask(taskArg.preTask, {x:x, touchedTasksArray: touchedTasksArray })
|
||||
} else {
|
||||
let done2 = plugins.Q.defer();
|
||||
let done2 = plugins.q.defer();
|
||||
done2.resolve(x);
|
||||
return done2.promise;
|
||||
}
|
||||
@ -68,7 +65,7 @@ export let runTask = function (taskArg: Task, optionsArg: {x?, touchedTasksArray
|
||||
if (taskArg.afterTask && !isTaskTouched(taskArg.afterTask, touchedTasksArray)) {
|
||||
return runTask(taskArg.afterTask, {x:x, touchedTasksArray: touchedTasksArray });
|
||||
} else {
|
||||
let done2 = plugins.Q.defer();
|
||||
let done2 = plugins.q.defer();
|
||||
done2.resolve(x);
|
||||
return done2.promise;
|
||||
}
|
||||
@ -85,7 +82,7 @@ export let runTask = function (taskArg: Task, optionsArg: {x?, touchedTasksArray
|
||||
|
||||
export interface cycleObject {
|
||||
cycleCounter:number,
|
||||
deferred:plugins.Q.Deferred<any>
|
||||
deferred: plugins.q.Deferred<any>
|
||||
}
|
||||
|
||||
export class CycleCounter {
|
||||
@ -95,7 +92,7 @@ export class CycleCounter {
|
||||
this.task = taskArg;
|
||||
};
|
||||
getPromiseForCycle(cycleCountArg:number){
|
||||
let done = plugins.Q.defer();
|
||||
let done = plugins.q.defer();
|
||||
let cycleObject:cycleObject = {
|
||||
cycleCounter:cycleCountArg,
|
||||
deferred:done
|
||||
|
@ -1,10 +1,6 @@
|
||||
import * as plugins from "./taskbuffer.plugins"
|
||||
import * as helpers from "./taskbuffer.classes.helpers"
|
||||
|
||||
//interfaces
|
||||
import {Promise} from "q";
|
||||
export {Promise} from "q";
|
||||
|
||||
export interface ITaskFunction {
|
||||
(x?:any):PromiseLike<any>;
|
||||
}
|
||||
@ -74,7 +70,7 @@ export class Task {
|
||||
if (stateArg == "locked"){
|
||||
this._state = "locked";
|
||||
} else {
|
||||
plugins.beautylog.error("state type " + stateArg.blue + " could not be set");
|
||||
plugins.beautylog.error("state type " + stateArg + " could not be set");
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ export class Taskchain extends Task {
|
||||
optionsArg,
|
||||
{
|
||||
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; // counter for iterating async over the taskArray
|
||||
let iterateTasks = (x) => {
|
||||
if(typeof this.taskArray[taskCounter] != "undefined"){
|
||||
|
@ -11,12 +11,12 @@ export class Taskparallel extends Task {
|
||||
optionsArg,
|
||||
{
|
||||
taskFunction: () => {
|
||||
let done = plugins.Q.defer();
|
||||
let promiseArray:PromiseLike<any>[] = []; // stores promises of all tasks, since they run in parallel
|
||||
let done = plugins.q.defer();
|
||||
let promiseArray: Promise<any>[] = []; // stores promises of all tasks, since they run in parallel
|
||||
this.taskArray.forEach(function (taskArg) {
|
||||
promiseArray.push(taskArg.trigger());
|
||||
})
|
||||
plugins.Q.all(promiseArray)
|
||||
Promise.all(promiseArray)
|
||||
.then(done.resolve);
|
||||
return done.promise;
|
||||
}
|
||||
|
@ -1,5 +1,12 @@
|
||||
import "typings-global"
|
||||
export import beautylog = require("beautylog");
|
||||
export import Q = require("q");
|
||||
export import lodash= require("lodash");
|
||||
export import rxjs = require("rxjs");
|
||||
import * as beautylog from "beautylog"
|
||||
import * as lodash from "lodash"
|
||||
import * as rxjs from "rxjs"
|
||||
import * as q from 'smartq'
|
||||
|
||||
export {
|
||||
beautylog,
|
||||
lodash,
|
||||
rxjs,
|
||||
q
|
||||
}
|
Reference in New Issue
Block a user