From 548a0086c5c34a84ab6998f00c03de1b7d090a3a Mon Sep 17 00:00:00 2001 From: "stefan.poeter@cloud-automation.de" Date: Sun, 27 Nov 2016 00:22:49 +0100 Subject: [PATCH] - Fixed error on the onError method. --- src/modbus-tcp-server-client.js | 2 +- test/heap-test-coils.js | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/modbus-tcp-server-client.js b/src/modbus-tcp-server-client.js index dc4a0c5..816a531 100644 --- a/src/modbus-tcp-server-client.js +++ b/src/modbus-tcp-server-client.js @@ -64,7 +64,7 @@ module.exports = stampit() this.onSocketError = function (e) { this.logError('Socker error', e) - } + }.bind(this) init() }) diff --git a/test/heap-test-coils.js b/test/heap-test-coils.js index 0b1f5cb..490b97e 100644 --- a/test/heap-test-coils.js +++ b/test/heap-test-coils.js @@ -2,6 +2,7 @@ const modbus = require('../') const v8 = require('v8') +const Promise = require('bluebird') const client = modbus.client.tcp.complete({ 'host': 'localhost', @@ -11,9 +12,21 @@ const client = modbus.client.tcp.complete({ client.connect() client.on('connect', function () { - for (var i = 1; i < 1e5; i++) { - client.readCoils(0, 13) + + let p = Promise.resolve() + + for (let i = 1; i < 1e5; i++) { + p = p.then(client.readCoils(0, 13)) } - console.log('Heap:', Math.floor(v8.getHeapStatistics().used_heap_size / 1e6), 'MB') + p.then(function () { + + let usedHeapSize = Math.floor(v8.getHeapStatistics().used_heap_size / 1e6); + + console.log('Heap:', usedHeapSize, 'MB') + + client.close() + + }) + })