From b2478d79f2e4f75698135dadfd56239fa20323a0 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Thu, 23 Jan 2020 15:24:46 +0000 Subject: [PATCH] fix(core): update --- test/test.ts | 2 +- ts/smartrule.classes.smartrule.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/test.ts b/test/test.ts index 8ae29de..4380e10 100644 --- a/test/test.ts +++ b/test/test.ts @@ -11,7 +11,7 @@ let testSmartruleInstance: smartrule.SmartRule; tap.test('first test', async () => { testSmartruleInstance = new smartrule.SmartRule(); testSmartruleInstance.createRule( - 0, + 2, async messageArg => { if (messageArg.body.startsWith('hello')) { return 'apply-stop'; diff --git a/ts/smartrule.classes.smartrule.ts b/ts/smartrule.classes.smartrule.ts index 4fecfb6..bf76788 100644 --- a/ts/smartrule.classes.smartrule.ts +++ b/ts/smartrule.classes.smartrule.ts @@ -26,8 +26,9 @@ export class SmartRule { }; // lets run the checks - const runNextBatch = async (startPriority: number): Promise => { - const nextBatch = getNextParallelBatch(0); + const runNextBatch = async (startPriority: number, runRulesAmount: number): Promise => { + const nextBatch = getNextParallelBatch(startPriority); + runRulesAmount = runRulesAmount + nextBatch.length; const outcomes: TTreeActionResult[] = []; for (const rule of nextBatch) { const checkResult = await rule.checkFunction(objectArg); @@ -50,14 +51,14 @@ export class SmartRule { } } - if (startPriority < this.rules[this.rules.length-1].priority) { - await runNextBatch(startPriority++); + if (runRulesAmount < this.rules.length) { + await runNextBatch((startPriority + 1), runRulesAmount); } else { return; } }; - await runNextBatch(0); + await runNextBatch(0,0); } public createRule(priorityArg: number, checkFunctionArg: TCheckFunc, actionFunctionArg: TActionFunc) {