globalcache
Advanced tools
Comparing version 2.4.0 to 2.5.0
24
index.js
var util = require('util'), | ||
request = require('request'), | ||
net = require('net'), | ||
events = require('events'), | ||
_ = require('underscore'), | ||
crypto = require('crypto'), | ||
EventEmitter = require('events').EventEmitter, | ||
@@ -40,4 +39,3 @@ ERRORCODES = { | ||
var | ||
callbacks = {}, | ||
var callbacks = {}, | ||
messageQueue = [], | ||
@@ -68,3 +66,3 @@ _currentRequestID = 0; | ||
var iTach = function (config) { | ||
function iTach(config) { | ||
config = _.extend({ | ||
@@ -79,3 +77,3 @@ port: 4998, | ||
} | ||
var self = this; | ||
var isSending = false; | ||
@@ -102,3 +100,3 @@ | ||
var _send = function () { | ||
var self = this; | ||
if (!messageQueue.length) { | ||
@@ -117,7 +115,9 @@ console.log('Message queue is empty. returning...') | ||
console.log('Connecting to ' + config.host + ':' + config.port); | ||
self.emit('connecting'); | ||
socket.on('connect', function () { | ||
console.log('node-itach :: connected to ' + config.host + ':' + config.port); | ||
console.log('node-itach :: sending data', data); | ||
self.emit('connected'); | ||
socket.write(data + "\r\n"); | ||
self.emit('send'); | ||
}); | ||
@@ -127,2 +127,3 @@ | ||
console.log('node-itach :: disconnected from ' + config.host + ':' + config.port); | ||
self.emit('disconnected'); | ||
}); | ||
@@ -134,2 +135,3 @@ | ||
socket.destroy(); | ||
self.emit('error', err); | ||
}); | ||
@@ -141,2 +143,3 @@ | ||
socket.destroy(); | ||
self.emit('error', 'Timeout'); | ||
}); | ||
@@ -146,2 +149,3 @@ | ||
var wholeData = data.toString().replace(/[\n\r]$/, ""); | ||
self.emit(data, wholeData); | ||
wholeData = wholeData.split(/\r/); | ||
@@ -244,5 +248,5 @@ console.log("node-itach :: received data: " + data); | ||
} | ||
; | ||
iTach.super_.call(this, config); | ||
} | ||
util.inherits(iTach, EventEmitter); | ||
module.exports = {iTach: iTach}; |
@@ -43,3 +43,3 @@ { | ||
}, | ||
"version": "2.4.0" | ||
"version": "2.5.0" | ||
} |
@@ -19,2 +19,22 @@ /** | ||
itach.on('connecting', function () { | ||
console.log('--------------connecting'); | ||
}); | ||
itach.on('connected', function () { | ||
console.log('--------------connected'); | ||
}); | ||
itach.on('disconnected', function () { | ||
console.log('--------------disconnected'); | ||
}); | ||
itach.on('send', function () { | ||
console.log('--------------send'); | ||
}); | ||
itach.on('data', function () { | ||
console.log('--------------data'); | ||
}); | ||
itach.send(itachRelay1, function (err, res) { | ||
@@ -21,0 +41,0 @@ if (err) { |
18288
288