Skip to content

Commit

Permalink
satisfied is not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpvar committed Oct 17, 2010
1 parent c34e028 commit b56bcd2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 40 deletions.
17 changes: 6 additions & 11 deletions lib/conductor.js
Expand Up @@ -145,6 +145,9 @@ function Edge(node, type) {
var ports = [],
self = this;

for (var i in this.ports) {
ports[i] = this.ports[i].value(context);
}

for (var c in self.node.edges.callback.ports) {
(function(port, index) {
Expand All @@ -153,17 +156,13 @@ function Edge(node, type) {
};
})(self.node.edges.callback.ports[c], c);
}


for (var i in this.ports) {
ports[i] = this.ports[i].value(context);
}
return ports;
};

this.satisfied = function(context) {
context.prepare(this.node);
var ports = context.nodes[node.index].edges[this.type].ports;

if (this.length() === 0) {
return true;
}
Expand All @@ -178,6 +177,7 @@ function Edge(node, type) {
}
}
}

for (var m=0; m<matches.length; m++) {
this.ports[m].join(matches[m], context);
}
Expand Down Expand Up @@ -298,11 +298,8 @@ function Node(fn, conductor, name) {
values = edge.values(context),
self = this;

if (this.isFork()) {
context = new Context(context, true);
}

setTimeout(function() {
console.log("EXEC", self.name + "(", values, ")", context.splits);
var result = fn.apply(context, values);
// The only output you can actually have is a return.. everything else
// is callback based
Expand Down Expand Up @@ -342,8 +339,6 @@ function Port(edge, index) {

if (context.nodes[node].edges[type].ports[port]) {
return context.nodes[node].edges[type].ports[port].value;
} else {
return undefined;
}
};

Expand Down
50 changes: 21 additions & 29 deletions test/test.js
Expand Up @@ -123,13 +123,13 @@ ok("a join node input edge is satisfied when all inputs are satisfied",
satisfyNode.edges.input.satisfied(satisfyContext));

// Satisfaction (callbacks)
/*
[scn1]
| |
| [scn2]
| |
[scn3]
*/

// [scn1]
// | |
// | [scn2]
// | |
// [scn3]


var satisfyCallbackConductor = conductor(),
scn1 = satisfyCallbackConductor.node(null, "scn1"),
Expand Down Expand Up @@ -282,62 +282,54 @@ pAsync.B.input(1, pAsync.C.input(0));
pAsync.C.output(pAsync.D.input(0));
pflow.execute();

/*

// Paralell Asynchronous Split/Join
var paspResults = [10,9,8,7,6,5,4,3,2,1],
paspflow = conductor(),
pasp = {
A : paspflow.node(function(cb1, cb2) {
console.log("in a");
var count = 10, loc = 1;
setTimeout(function paspnext() {
console.log("calling cb1", loc);
cb1(loc);
loc++;
console.log("calling cb2", loc);
cb2(loc);
loc++;
if (loc <= count) {
setTimeout(paspnext, 0);
}
}, 0);
console.log("exiting a");
}),
}, "pasp-A"),
B : paspflow.node(function(value, fn) {
console.log("in b", value);
setTimeout(function() {
if (typeof fn === "function") {
fn(value);
}
}, 1000/value);
}),
}, "pasp-B"),
C : paspflow.node(function(value) {
console.log("in c", value);
return value;
}),
}, "pasp-C"),
D : paspflow.node(function(v1, v2) {
console.log("in d:", v1, v2);
console.log("in D");
return v1+ "" + v2;
}),
}, "pasp-D"),
E : paspflow.node(function(value) {
console.log("in e", value);
var ex = paspResults.shift();
ok("parallel split/join results should be " + ex + " not " + value,
value === ex);
})
}, "pasp-E")
};

pasp.B.input(0, pasp.A.input(0));
pasp.C.input(0, pasp.A.input(1));
pasp.D.input(0, pasp.B.input(1));
pasp.D.input(1, pasp.C.output(0));
pasp.E.input(0, pasp.D.output(0));
pasp.A.input(0, pasp.B.input(0));
pasp.A.input(1, pasp.C.input(0));
pasp.B.input(1, pasp.D.input(0));
pasp.C.output(pasp.D.input(1));
pasp.D.output(pasp.E.input(0));
paspflow.execute();
*/

//
// RESULTS
//
process.on("exit", function() {

console.log("Exiting!");
for (var i=0; i<tests.length; i++) {
if (tests[i].error) {
Expand Down

0 comments on commit b56bcd2

Please sign in to comment.