Skip to content

Commit

Permalink
Add better error handling to nanomsg.
Browse files Browse the repository at this point in the history
  • Loading branch information
ludost committed Feb 20, 2018
1 parent 6bb3476 commit ac76dee
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/transport/nanomsg/NanoMsgConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,23 @@ NanoMsgConnection.prototype.getMyUrl = function () {
* @return {Promise} returns a promise which resolves when the message has been sent
*/
NanoMsgConnection.prototype.send = function (to, message) {
if (!this.outSockets[to]) {
this.outSockets[to] = NanoMsg.socket('push', this.socketConfig);
this.outSockets[to].dontwait(true);
this.outSockets[to].connect(to.replace(this.transport.type + ":", ""))
}
if (!this.outSockets[to].sessionId) {
this.outSockets[to].send(this.getMyUrl() + "|" + JSON.stringify(message));
} else {
this.outSockets[to].send(this.outSockets[to].sessionId + "|" + JSON.stringify(message));
try {
if (!this.outSockets[to]) {
this.outSockets[to] = NanoMsg.socket('push', this.socketConfig);
this.outSockets[to].dontwait(true);
this.outSockets[to].connect(to.replace(this.transport.type + ":", ""))
}
if (!this.outSockets[to].sessionId) {
this.outSockets[to].send(this.getMyUrl() + "|" + JSON.stringify(message));
} else {
this.outSockets[to].send(this.outSockets[to].sessionId + "|" + JSON.stringify(message));
}
return Promise.resolve();
} catch (e){
console.log("NanoMsg failed to send message to:",to," msg:",message," err:",e);
return Promise.reject();
}
return Promise.resolve();

};

/**
Expand Down

0 comments on commit ac76dee

Please sign in to comment.