Skip to content

Commit aa6cce7

Browse files
committed
Merge pull request #80 from doug-martin/master
v0.1.14
2 parents 5283dfb + 3aadd45 commit aa6cce7

File tree

8 files changed

+81
-24
lines changed

8 files changed

+81
-24
lines changed

docs/History.html

+4
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@
178178

179179

180180

181+
<h1>0.1.14</h1>
182+
<ul>
183+
<li>Fixed issue with async actions and early match termination.</li>
184+
</ul>
181185
<h1>0.1.13</h1>
182186
<ul>
183187
<li>Fixed issue <a href="https://github.com/C2FO/nools/issues/68">#68</a> where <code>matchUntilHalt</code> uses a lot of CPU</li>

docs/nools.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

history.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#0.1.14
2+
* Fixed issue with async actions and early match termination.
3+
4+
15
#0.1.13
26
* Fixed issue [#68](https://github.com/C2FO/nools/issues/68) where `matchUntilHalt` uses a lot of CPU
37
* Fixed issue [#45](https://github.com/C2FO/nools/issues/45), now compiled rules support `or` constraint with more than 2 inner constraints.

lib/executionStrategy.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ Promise.extend({
4747
},
4848

4949
__handleAsyncNext: function (next) {
50-
var self = this;
50+
var self = this, agenda = self.agenda;
5151
return next.addCallback(function () {
5252
self.looping = false;
53-
if (self.flowAltered) {
54-
self.rootNode.incrementCounter();
55-
self.flowAltered = false;
53+
if (!agenda.isEmpty()) {
54+
if (self.flowAltered) {
55+
self.rootNode.incrementCounter();
56+
self.flowAltered = false;
57+
}
5658
if (!self.__halted) {
5759
self.callNext();
5860
} else {
@@ -67,9 +69,11 @@ Promise.extend({
6769

6870
__handleSyncNext: function (next) {
6971
this.looping = false;
70-
if (this.flowAltered) {
71-
this.rootNode.incrementCounter();
72-
this.flowAltered = false;
72+
if (!this.agenda.isEmpty()) {
73+
if (this.flowAltered) {
74+
this.rootNode.incrementCounter();
75+
this.flowAltered = false;
76+
}
7377
}
7478
if (next && !this.__halted) {
7579
nextTick(this.callNext);
@@ -88,7 +92,7 @@ Promise.extend({
8892
callNext: function () {
8993
this.looping = true;
9094
var next = this.agenda.fireNext();
91-
return isPromiseLike(next) ? this.__handleAsyncNext(next) : this.__handleSyncNext(next);
95+
return isPromiseLike(next) ? this.__handleAsyncNext(next): this.__handleSyncNext(next);
9296
},
9397

9498
execute: function () {

nools.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -1356,12 +1356,14 @@ Promise.extend({
13561356
},
13571357

13581358
__handleAsyncNext: function (next) {
1359-
var self = this;
1359+
var self = this, agenda = self.agenda;
13601360
return next.addCallback(function () {
13611361
self.looping = false;
1362-
if (self.flowAltered) {
1363-
self.rootNode.incrementCounter();
1364-
self.flowAltered = false;
1362+
if (!agenda.isEmpty()) {
1363+
if (self.flowAltered) {
1364+
self.rootNode.incrementCounter();
1365+
self.flowAltered = false;
1366+
}
13651367
if (!self.__halted) {
13661368
self.callNext();
13671369
} else {
@@ -1376,9 +1378,11 @@ Promise.extend({
13761378

13771379
__handleSyncNext: function (next) {
13781380
this.looping = false;
1379-
if (this.flowAltered) {
1380-
this.rootNode.incrementCounter();
1381-
this.flowAltered = false;
1381+
if (!this.agenda.isEmpty()) {
1382+
if (this.flowAltered) {
1383+
this.rootNode.incrementCounter();
1384+
this.flowAltered = false;
1385+
}
13821386
}
13831387
if (next && !this.__halted) {
13841388
nextTick(this.callNext);
@@ -1397,7 +1401,7 @@ Promise.extend({
13971401
callNext: function () {
13981402
this.looping = true;
13991403
var next = this.agenda.fireNext();
1400-
return isPromiseLike(next) ? this.__handleAsyncNext(next) : this.__handleSyncNext(next);
1404+
return isPromiseLike(next) ? this.__handleAsyncNext(next): this.__handleSyncNext(next);
14011405
},
14021406

14031407
execute: function () {

nools.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nools",
33
"description": "A rules engine for node",
4-
"version": "0.1.13",
4+
"version": "0.1.14",
55
"bin": {
66
"nools": "./bin/nools"
77
},

test/flow.test.js

+42-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ it.describe("nools", function (it) {
6060
var name = "delete nools flows";
6161
nools.flow(name);
6262
assert.isTrue(nools.hasFlow(name));
63-
debugger;
6463
assert.equal(nools.deleteFlows(), nools);
6564
assert.isFalse(nools.hasFlow(name));
6665
});
@@ -690,6 +689,48 @@ it.describe("Flow", function (it) {
690689
});
691690
});
692691

692+
it.describe("async actions", function (it) {
693+
694+
var flow;
695+
696+
it.timeout(2000);
697+
698+
function Message(m) {
699+
this.message = m;
700+
}
701+
702+
703+
it.beforeAll(function () {
704+
flow = nools.flow("async flow", function () {
705+
this.rule("Hello", [Message, "m", "m.message == 'hello'"], function (facts, engine, next) {
706+
setTimeout(function () {
707+
next();
708+
}, 500);
709+
});
710+
711+
this.rule("Goodbye", [Message, "m", "m.message == 'hello goodbye'"], function (facts, engine, next) {
712+
setTimeout(function () {
713+
next();
714+
}, 500);
715+
});
716+
717+
});
718+
});
719+
720+
it.should("fire all rules", function () {
721+
var fired = [];
722+
var session = flow.getSession(new Message("hello"), new Message("hello goodbye"))
723+
.on("fire", function (name) {
724+
debugger;
725+
fired.push(name);
726+
});
727+
return session.match().then(function () {
728+
assert.deepEqual(fired, ["Goodbye", "Hello"]);
729+
})
730+
});
731+
732+
});
733+
693734
it.describe("#matchUntilHalt", function (it) {
694735
function Message(m) {
695736
this.message = m;

0 commit comments

Comments
 (0)