mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +00:00
after socket closes, complete pending requests with errors
This commit is contained in:
parent
e0e4ffe0f4
commit
73312cb920
1 changed files with 22 additions and 2 deletions
|
@ -62,9 +62,10 @@ class JsonRPC {
|
||||||
if (_requestQueue.isNotEmpty) {
|
if (_requestQueue.isNotEmpty) {
|
||||||
// TODO iterate over the remaining requests and if they are not isComplete then complete the completer with an error
|
// TODO iterate over the remaining requests and if they are not isComplete then complete the completer with an error
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"JsonRPC doneHandler: queue not empty but connection closed",
|
"JsonRPC doneHandler: queue not empty but connection closed, completing pending requests with errors",
|
||||||
level: LogLevel.Warning,
|
level: LogLevel.Error,
|
||||||
);
|
);
|
||||||
|
_errorPendingRequests();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +92,25 @@ class JsonRPC {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _errorPendingRequests() {
|
||||||
|
if (_requestQueue.isNotEmpty) {
|
||||||
|
final req = _requestQueue.next;
|
||||||
|
if (!(req.isComplete)) {
|
||||||
|
req.completer.completeError('JsonRPC doneHandler: socket closed before request could complete');
|
||||||
|
_requestQueue.remove(req).then((ret) {
|
||||||
|
if (_requestQueue.isNotEmpty) {
|
||||||
|
_errorPendingRequests();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Logging.instance.log(
|
||||||
|
"JsonRPC _errorPendingRequests: done completing pending requests with errors",
|
||||||
|
level: LogLevel.Info,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<dynamic> request(String jsonRpcRequest) async {
|
Future<dynamic> request(String jsonRpcRequest) async {
|
||||||
// todo: handle this better?
|
// todo: handle this better?
|
||||||
// Do we need to check the subscription, too?
|
// Do we need to check the subscription, too?
|
||||||
|
|
Loading…
Reference in a new issue