Gate node using Blockly

@cymplecy my idea of a gate is slightly different: I don't want to discard messages if the gate is closed but I want to queue them ... then an external event opens the gate, which lets one message pass through and the gate is closed again until the next "open" event ...

I've done it using a function node, here's the code, if anyone's interested ...

// simple gate ...
// starts open
// when a (non-gate-control) message arrives:
//  - msg is transferred if gate is open and then gate is closed no matter what
//  - msg is queued if gate is closed
// gate can only be opened by external specific message
// when gate is opened, it lets through ONE msg and then gate is closed again
// gate control is done using msg.gate: {open: true/false, reset: true/false}
// note: msg.gate.reset will clear the msg queue

// default value when reset
var resetGate = {'open': true, 'msgs': []};

var nodeStatus = function() {
    var gate = context.get('gate') || resetGate ;
    node.status({
        "fill": (gate.open ? "green" : "red"), 
        "shape": "dot", 
        "text": (gate.open ?  "Open" : "Msg: " + gate.msgs.length ) 
    });
}

node.on('close', function() {
    // reset msgs ...
    context.set('gate', resetGate ); 
    nodeStatus();
});

var gate = context.get('gate') || resetGate ;

if (msg.gate) {
// checking explicitly true/false for msg.gate.open 
    if (msg.gate.open===true) gate.open = true;
    else if (msg.gate.open===false) gate.open = false;
    if (msg.gate.reset) gate = resetGate;
} else {
    // add msg to queue
    gate.msgs.push(msg);
}

if (gate.open && gate.msgs.length>0) {
    new_msg = gate.msgs.splice(0,1);
    nodeStatus();
    node.send(new_msg);
    gate.open = false;
}

nodeStatus();

context.set("gate",gate);

return null;