Skip to content

Commit

Permalink
v0.1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed Oct 2, 2013
1 parent 4aadfe6 commit 3aadd45
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 24 deletions.
4 changes: 4 additions & 0 deletions docs/History.html
Expand Up @@ -178,6 +178,10 @@



<h1>0.1.14</h1>
<ul>
<li>Fixed issue with async actions and early match termination.</li>
</ul>
<h1>0.1.13</h1>
<ul>
<li>Fixed issue <a href="https://github.com/C2FO/nools/issues/68">#68</a> where <code>matchUntilHalt</code> uses a lot of CPU</li>
Expand Down
6 changes: 3 additions & 3 deletions docs/nools.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions history.md
@@ -1,3 +1,7 @@
#0.1.14
* Fixed issue with async actions and early match termination.


#0.1.13
* Fixed issue [#68](https://github.com/C2FO/nools/issues/68) where `matchUntilHalt` uses a lot of CPU
* Fixed issue [#45](https://github.com/C2FO/nools/issues/45), now compiled rules support `or` constraint with more than 2 inner constraints.
Expand Down
20 changes: 12 additions & 8 deletions lib/executionStrategy.js
Expand Up @@ -47,12 +47,14 @@ Promise.extend({
},

__handleAsyncNext: function (next) {
var self = this;
var self = this, agenda = self.agenda;
return next.addCallback(function () {
self.looping = false;
if (self.flowAltered) {
self.rootNode.incrementCounter();
self.flowAltered = false;
if (!agenda.isEmpty()) {
if (self.flowAltered) {
self.rootNode.incrementCounter();
self.flowAltered = false;
}
if (!self.__halted) {
self.callNext();
} else {
Expand All @@ -67,9 +69,11 @@ Promise.extend({

__handleSyncNext: function (next) {
this.looping = false;
if (this.flowAltered) {
this.rootNode.incrementCounter();
this.flowAltered = false;
if (!this.agenda.isEmpty()) {
if (this.flowAltered) {
this.rootNode.incrementCounter();
this.flowAltered = false;
}
}
if (next && !this.__halted) {
nextTick(this.callNext);
Expand All @@ -88,7 +92,7 @@ Promise.extend({
callNext: function () {
this.looping = true;
var next = this.agenda.fireNext();
return isPromiseLike(next) ? this.__handleAsyncNext(next) : this.__handleSyncNext(next);
return isPromiseLike(next) ? this.__handleAsyncNext(next): this.__handleSyncNext(next);
},

execute: function () {
Expand Down
20 changes: 12 additions & 8 deletions nools.js
Expand Up @@ -1356,12 +1356,14 @@ Promise.extend({
},

__handleAsyncNext: function (next) {
var self = this;
var self = this, agenda = self.agenda;
return next.addCallback(function () {
self.looping = false;
if (self.flowAltered) {
self.rootNode.incrementCounter();
self.flowAltered = false;
if (!agenda.isEmpty()) {
if (self.flowAltered) {
self.rootNode.incrementCounter();
self.flowAltered = false;
}
if (!self.__halted) {
self.callNext();
} else {
Expand All @@ -1376,9 +1378,11 @@ Promise.extend({

__handleSyncNext: function (next) {
this.looping = false;
if (this.flowAltered) {
this.rootNode.incrementCounter();
this.flowAltered = false;
if (!this.agenda.isEmpty()) {
if (this.flowAltered) {
this.rootNode.incrementCounter();
this.flowAltered = false;
}
}
if (next && !this.__halted) {
nextTick(this.callNext);
Expand All @@ -1397,7 +1401,7 @@ Promise.extend({
callNext: function () {
this.looping = true;
var next = this.agenda.fireNext();
return isPromiseLike(next) ? this.__handleAsyncNext(next) : this.__handleSyncNext(next);
return isPromiseLike(next) ? this.__handleAsyncNext(next): this.__handleSyncNext(next);
},

execute: function () {
Expand Down
6 changes: 3 additions & 3 deletions nools.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "nools",
"description": "A rules engine for node",
"version": "0.1.13",
"version": "0.1.14",
"bin": {
"nools": "./bin/nools"
},
Expand Down
43 changes: 42 additions & 1 deletion test/flow.test.js
Expand Up @@ -60,7 +60,6 @@ it.describe("nools", function (it) {
var name = "delete nools flows";
nools.flow(name);
assert.isTrue(nools.hasFlow(name));
debugger;
assert.equal(nools.deleteFlows(), nools);
assert.isFalse(nools.hasFlow(name));
});
Expand Down Expand Up @@ -690,6 +689,48 @@ it.describe("Flow", function (it) {
});
});

it.describe("async actions", function (it) {

var flow;

it.timeout(2000);

function Message(m) {
this.message = m;
}


it.beforeAll(function () {
flow = nools.flow("async flow", function () {
this.rule("Hello", [Message, "m", "m.message == 'hello'"], function (facts, engine, next) {
setTimeout(function () {
next();
}, 500);
});

this.rule("Goodbye", [Message, "m", "m.message == 'hello goodbye'"], function (facts, engine, next) {
setTimeout(function () {
next();
}, 500);
});

});
});

it.should("fire all rules", function () {
var fired = [];
var session = flow.getSession(new Message("hello"), new Message("hello goodbye"))
.on("fire", function (name) {
debugger;
fired.push(name);
});
return session.match().then(function () {
assert.deepEqual(fired, ["Goodbye", "Hello"]);
})
});

});

it.describe("#matchUntilHalt", function (it) {
function Message(m) {
this.message = m;
Expand Down

0 comments on commit 3aadd45

Please sign in to comment.