diff --git a/src/nodeClass.js b/src/nodeClass.js index 97ec545..637ec5b 100644 --- a/src/nodeClass.js +++ b/src/nodeClass.js @@ -21,6 +21,8 @@ class nodeClass { this._attachInputHandler(); this._registerChild(); + this._startTickLoop(); + this._attachCloseHandler(); } /** @@ -32,7 +34,6 @@ class nodeClass { switch (msg.topic) { case "clock": this.source.updateState(msg.timestamp); - send([this.source.getEffluent, null, null]); send([msg, null, null]); break; case "Fluent": @@ -137,6 +138,22 @@ class nodeClass { this.node.source = this.source; } + _startTickLoop() { + setTimeout(() => { + this._tickInterval = setInterval(() => this._tick(), 1000); + }, 1000); + } + + _tick(){ + this.node.send([this.source.getEffluent, null, null]); + } + + _attachCloseHandler() { + this.node.on('close', (done) => { + clearInterval(this._tickInterval); + done(); + }); + } } module.exports = nodeClass; \ No newline at end of file