Skip to content

Commit 3b7755f

Browse files
committed
Fixed bug that occurred when process with a 'count' signal returned empty data (data=[])
1 parent 16edffd commit 3b7755f

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

engine2/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ Engine.prototype.emitSignals = function(sigs, cb) {
191191
async.each(sigs, function iterator(sig, doneIter) {
192192
var sigInstances = [];
193193
sig._ts = timeStamp;
194+
// FIXME: if there is no 'data', a "pure-metadata" signal will be sent. However, if there is a 'data=[]' (empty),
195+
// no signals will be sent! It seems to work well with the semantics of 'count' signals, but should be tested
194196
if (sig.data) { // there is a 'data' array which may contain multiple instances of this signal
195197
for (var i in sig.data) {
196198
var s = copySignal(sig);

engine2/process.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,22 +358,24 @@ var ProcLogic = function() {
358358
var countSigId = proc.fullInfo.outcounts &&
359359
proc.fullInfo.outcounts[funcOuts[i]] ? proc.fullInfo.outcounts[funcOuts[i]]: undefined;
360360
if (countSigId) {
361-
var count = outValues[i].data ? outValues[i].data.length: 1;
361+
var count = outValues[i].data ? outValues[i].data.length: 1;
362362
var sigId = countSigId.split(":")[1];
363363

364364
//onsole.log("FUNC OUTS", funcOuts);
365365
//onsole.log("EMITTING COUNT SIG", sigId);
366366
//onsole.log("IN COUNTS", proc.fullInfo.incounts);
367367
//onsole.log("OUT COUNTS", proc.fullInfo.outcounts);
368368
var sigV = {"_id": +sigId, "count": count, "control": "count", data: [{}]};
369-
if (!proc.fullInfo.ordering) {
370-
proc.engine.emitSignals([sigV]);
371-
} else {
372-
// TODO: test thouroughly if ordering works correctly with output "count" signals
373-
function Arg() {} // we need an Array-like object
374-
Arg.prototype = Object.create(Array.prototype);
375-
proc.emitStash[firingId] = new Arg;
376-
proc.emitStash[firingId].push(sigV);
369+
if (count > 0) { // 0 can happen if process returns an empty "data" array
370+
if (!proc.fullInfo.ordering) {
371+
proc.engine.emitSignals([sigV]);
372+
} else {
373+
// TODO: test thouroughly if ordering works correctly with output "count" signals
374+
function Arg() {} // we need an Array-like object
375+
Arg.prototype = Object.create(Array.prototype);
376+
proc.emitStash[firingId] = new Arg;
377+
proc.emitStash[firingId].push(sigV);
378+
}
377379
}
378380
}
379381
}

0 commit comments

Comments
 (0)