Is adding a callback to a event okay? Like so?
Client.prototype.send = function(data, cb) {
// convert json to string
data = JSON.stringify(data)
this.client.write(data)
// wait for the response of this request
this.client.on('data', function(data) {
var request = JSON.parse(data)
// return response as callback
if (request.type === data.type) {
cb(request)
}
})
}
Then invoked like:
// send request and wait for reply
client.send(data, function(response) {
// do stuff to reply/response
// this executes +1 times for every sent request should only do 1 request 1 response
console.log(response)
})
Do it do the callback every time the same type of event is emitted?
Does this make performance suffer?