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() + + }) + })