Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

v0.1.14 #80

Merged
merged 1 commit into from

1 participant

@doug-martin
Owner

No description provided.

@doug-martin doug-martin merged commit aa6cce7 into C2FO:master
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.
View
4 docs/History.html
@@ -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>
View
6 docs/nools.js
3 additions, 3 deletions not shown
View
4 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.
View
20 lib/executionStrategy.js
@@ -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 () {
View
20 nools.js
@@ -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 () {
View
6 nools.min.js
3 additions, 3 deletions not shown
View
2  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"
},
View
43 test/flow.test.js
@@ -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.