mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 03:28:07 +00:00
add optional sync send
This commit is contained in:
parent
5203d1fc3e
commit
cd92d44098
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user