mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
update timer for compliter
This commit is contained in:
parent
24354b0864
commit
a2af1e1ff7
1 changed files with 11 additions and 6 deletions
|
@ -124,6 +124,7 @@ class ElectrumClient {
|
|||
await callWithTimeout(method: 'server.ping');
|
||||
_setIsConnected(true);
|
||||
} on RequestFailedTimeoutException catch (_) {
|
||||
print('RequestFailedTimeoutException');
|
||||
_setIsConnected(false);
|
||||
}
|
||||
}
|
||||
|
@ -356,23 +357,27 @@ class ElectrumClient {
|
|||
}
|
||||
|
||||
Future<dynamic> callWithTimeout(
|
||||
{required String method,
|
||||
List<Object> params = const [],
|
||||
int timeout = 3000}) async {
|
||||
{required String method, List<Object> params = const [], int timeout = 1000}) async {
|
||||
try {
|
||||
final completer = Completer<dynamic>();
|
||||
_id += 1;
|
||||
final id = _id;
|
||||
_registryTask(id, completer);
|
||||
socket!.write(jsonrpc(method: method, id: id, params: params));
|
||||
Timer(Duration(milliseconds: timeout), () {
|
||||
if (!completer.isCompleted) {
|
||||
var counter = 0;
|
||||
Timer.periodic(Duration(milliseconds: timeout), (timer) {
|
||||
if (!completer.isCompleted && counter > 5) {
|
||||
timer.cancel();
|
||||
completer.completeError(RequestFailedTimeoutException(method, id));
|
||||
} else if (completer.isCompleted) {
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
counter++;
|
||||
});
|
||||
|
||||
return completer.future;
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue