Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

v0.1.14 #80

Merged
merged 1 commit into from

1 participant

Doug Martin
Doug Martin
Owner

No description provided.

Doug Martin doug-martin merged commit aa6cce7 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 2, 2013
  1. Doug Martin

    v0.1.14

    doug-martin authored
This page is out of date. Refresh to see the latest.
4 docs/History.html
View
@@ -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>
6 docs/nools.js
View
3 additions, 3 deletions not shown
4 history.md
View
@@ -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.
20 lib/executionStrategy.js
View
@@ -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 {
@@ -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);
@@ -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 () {
20 nools.js
View
@@ -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 {
@@ -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);
@@ -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 () {
6 nools.min.js
View
3 additions, 3 deletions not shown
2  package.json
View
@@ -1,7 +1,7 @@
{
"name": "nools",
"description": "A rules engine for node",
- "version": "0.1.13",
+ "version": "0.1.14",
"bin": {
"nools": "./bin/nools"
},
43 test/flow.test.js
View
@@ -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));
});
@@ -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;
Something went wrong with that request. Please try again.