mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-22 02:24:30 +00:00
add timeout to requests
This commit is contained in:
parent
0955fdb6e6
commit
a2cdc4cdfa
1 changed files with 14 additions and 0 deletions
|
@ -97,6 +97,8 @@ class JsonRPC {
|
|||
final req = _requestQueue.next;
|
||||
|
||||
_socket!.write('${req.jsonRequest}\r\n');
|
||||
|
||||
req.initiateTimeout(const Duration(seconds: 10));
|
||||
// Logging.instance.log(
|
||||
// "JsonRPC request: wrote request ${req.jsonRequest} "
|
||||
// "to socket $host:$port",
|
||||
|
@ -214,5 +216,17 @@ class _JsonRPCRequest {
|
|||
}
|
||||
}
|
||||
|
||||
void initiateTimeout(Duration timeout) {
|
||||
Future<void>.delayed(timeout).then((_) {
|
||||
if (!isComplete) {
|
||||
try {
|
||||
throw Exception("_JsonRPCRequest timed out: $jsonRequest");
|
||||
} catch (e, s) {
|
||||
completer.completeError(e, s);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool get isComplete => completer.isCompleted;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue