fix(core): update

This commit is contained in:
Philipp Kunz 2020-01-23 15:24:46 +00:00
parent 917e630554
commit b2478d79f2
2 changed files with 7 additions and 6 deletions

View File

@ -11,7 +11,7 @@ let testSmartruleInstance: smartrule.SmartRule<ITestMessage>;
tap.test('first test', async () => { tap.test('first test', async () => {
testSmartruleInstance = new smartrule.SmartRule<ITestMessage>(); testSmartruleInstance = new smartrule.SmartRule<ITestMessage>();
testSmartruleInstance.createRule( testSmartruleInstance.createRule(
0, 2,
async messageArg => { async messageArg => {
if (messageArg.body.startsWith('hello')) { if (messageArg.body.startsWith('hello')) {
return 'apply-stop'; return 'apply-stop';

View File

@ -26,8 +26,9 @@ export class SmartRule<T> {
}; };
// lets run the checks // lets run the checks
const runNextBatch = async (startPriority: number): Promise<void> => { const runNextBatch = async (startPriority: number, runRulesAmount: number): Promise<void> => {
const nextBatch = getNextParallelBatch(0); const nextBatch = getNextParallelBatch(startPriority);
runRulesAmount = runRulesAmount + nextBatch.length;
const outcomes: TTreeActionResult[] = []; const outcomes: TTreeActionResult[] = [];
for (const rule of nextBatch) { for (const rule of nextBatch) {
const checkResult = await rule.checkFunction(objectArg); const checkResult = await rule.checkFunction(objectArg);
@ -50,14 +51,14 @@ export class SmartRule<T> {
} }
} }
if (startPriority < this.rules[this.rules.length-1].priority) { if (runRulesAmount < this.rules.length) {
await runNextBatch(startPriority++); await runNextBatch((startPriority + 1), runRulesAmount);
} else { } else {
return; return;
} }
}; };
await runNextBatch(0); await runNextBatch(0,0);
} }
public createRule(priorityArg: number, checkFunctionArg: TCheckFunc<T>, actionFunctionArg: TActionFunc) { public createRule(priorityArg: number, checkFunctionArg: TCheckFunc<T>, actionFunctionArg: TActionFunc) {