2 Commits

Author SHA1 Message Date
e67fbfebf6 1.0.7 2020-01-23 15:24:47 +00:00
b2478d79f2 fix(core): update 2020-01-23 15:24:46 +00:00
4 changed files with 9 additions and 8 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartrule",
"version": "1.0.6",
"version": "1.0.7",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartrule",
"version": "1.0.6",
"version": "1.0.7",
"private": false,
"description": "a smart rule library for handling decision trees.",
"main": "dist/index.js",

View File

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

View File

@@ -26,8 +26,9 @@ export class SmartRule<T> {
};
// lets run the checks
const runNextBatch = async (startPriority: number): Promise<void> => {
const nextBatch = getNextParallelBatch(0);
const runNextBatch = async (startPriority: number, runRulesAmount: number): Promise<void> => {
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<T> {
}
}
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<T>, actionFunctionArg: TActionFunc) {