From ee2d91fb4afdd3e909f7223070ce6e12c94c14b3 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 8 Sep 2023 16:26:10 +0100 Subject: [PATCH] Handle nodes with multiple input handlers properly Fixes #4330 --- .../@node-red/runtime/lib/nodes/Node.js | 15 ++++++---- .../@node-red/runtime/lib/nodes/Node_spec.js | 29 +++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/node_modules/@node-red/runtime/lib/nodes/Node.js b/packages/node_modules/@node-red/runtime/lib/nodes/Node.js index 7a7445a92..5a60cf6a0 100644 --- a/packages/node_modules/@node-red/runtime/lib/nodes/Node.js +++ b/packages/node_modules/@node-red/runtime/lib/nodes/Node.js @@ -42,6 +42,7 @@ function Node(n) { this._closeCallbacks = []; this._inputCallback = null; this._inputCallbacks = null; + this._expectedDoneCount = 0; if (n.name) { this.name = n.name; @@ -159,6 +160,9 @@ Node.prototype.on = function(event, callback) { if (event == "close") { this._closeCallbacks.push(callback); } else if (event === "input") { + if (callback.length === 3) { + this._expectedDoneCount++ + } if (this._inputCallback) { this._inputCallbacks = [this._inputCallback, callback]; this._inputCallback = null; @@ -218,19 +222,17 @@ Node.prototype._emitInput = function(arg) { } else if (node._inputCallbacks) { // Multiple callbacks registered. Call each one, tracking eventual completion var c = node._inputCallbacks.length; + let doneCount = 0 for (var i=0;i