add optional sync send

This commit is contained in:
Fabian Vogelsteller 2015-06-24 19:10:36 +02:00
parent 5203d1fc3e
commit cd92d44098

View File

@ -40,9 +40,9 @@ var IpcProvider = function (path, net) {
throw errors.InvalidConnection(path);
}
this.connection.on('error', function(e){
throw errors.InvalidConnection(path);
});
// this.connection.on('error', function(e){
// throw errors.InvalidConnection(path);
// });
@ -101,7 +101,26 @@ IpcProvider.prototype.isConnected = function() {
};
IpcProvider.prototype.send = function (payload) {
throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.');
if(this.connection.writeSync) {
// try reconnect, when connection is gone
if(!this.connection._handle)
this.connection.connect({path: this.path});
var result = this.connection.writeSync(JSON.stringify(payload));
try {
result = JSON.parse(result);
} catch(e) {
throw errors.InvalidResponse(result);
}
return result;
} else {
throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.');
}
};
IpcProvider.prototype.sendAsync = function (payload, callback) {