mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add timeout option to link-call node
This commit is contained in:
parent
1931395fdb
commit
dfd9364061
@ -28,6 +28,10 @@
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-timeout"><span data-i18n="exec.label.timeout"></span></label>
|
||||
<input type="text" id="node-input-timeout" placeholder="30" style="width: 70px; margin-right: 5px;"><span data-i18n="inject.seconds"></span>
|
||||
</div>
|
||||
<div style="position:relative; height: 30px; text-align: right;"><div style="display:inline-block"><input type="text" id="node-input-link-target-filter"></div></div>
|
||||
<div class="form-row node-input-link-row"></div>
|
||||
</script>
|
||||
@ -240,7 +244,8 @@
|
||||
color:"#ddd",//"#87D8CF",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
links: { value: [], type:"link in[]"}
|
||||
links: { value: [], type:"link in[]"},
|
||||
timeout: { value: "30", validate:RED.validators.number(true) }
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
|
@ -76,6 +76,10 @@ module.exports = function(RED) {
|
||||
const node = this;
|
||||
const target = n.links[0];
|
||||
const messageEvents = {};
|
||||
let timeout = parseFloat(n.timeout || "30")*1000;
|
||||
if (isNaN(timeout)) {
|
||||
timeout = 30000;
|
||||
}
|
||||
|
||||
this.on("input", function(msg, send, done) {
|
||||
msg._linkSource = msg._linkSource || [];
|
||||
@ -83,7 +87,14 @@ module.exports = function(RED) {
|
||||
id: crypto.randomBytes(14).toString('hex'),
|
||||
node: node.id,
|
||||
}
|
||||
messageEvents[messageEvent.id] = { send, done };
|
||||
messageEvents[messageEvent.id] = {
|
||||
msg: RED.util.cloneMessage(msg),
|
||||
send,
|
||||
done,
|
||||
ts: setTimeout(function() {
|
||||
timeoutMessage(messageEvent.id)
|
||||
}, timeout )
|
||||
};
|
||||
msg._linkSource.push(messageEvent);
|
||||
var targetNode = RED.nodes.getNode(target);
|
||||
if (targetNode) {
|
||||
@ -97,6 +108,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
const messageEvent = messageEvents[eventId];
|
||||
if (messageEvent) {
|
||||
clearTimeout(messageEvent.ts);
|
||||
delete messageEvents[eventId];
|
||||
messageEvent.send(msg);
|
||||
messageEvent.done();
|
||||
@ -104,6 +116,15 @@ module.exports = function(RED) {
|
||||
node.send(msg);
|
||||
}
|
||||
}
|
||||
|
||||
function timeoutMessage(eventId) {
|
||||
const messageEvent = messageEvents[eventId];
|
||||
if (messageEvent) {
|
||||
delete messageEvents[eventId];
|
||||
node.error("timeout",messageEvent.msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
RED.nodes.registerType("link call",LinkCallNode);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user