mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 03:59:23 +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');
|
await callWithTimeout(method: 'server.ping');
|
||||||
_setIsConnected(true);
|
_setIsConnected(true);
|
||||||
} on RequestFailedTimeoutException catch (_) {
|
} on RequestFailedTimeoutException catch (_) {
|
||||||
|
print('RequestFailedTimeoutException');
|
||||||
_setIsConnected(false);
|
_setIsConnected(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,23 +357,27 @@ class ElectrumClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> callWithTimeout(
|
Future<dynamic> callWithTimeout(
|
||||||
{required String method,
|
{required String method, List<Object> params = const [], int timeout = 1000}) async {
|
||||||
List<Object> params = const [],
|
|
||||||
int timeout = 3000}) async {
|
|
||||||
try {
|
try {
|
||||||
final completer = Completer<dynamic>();
|
final completer = Completer<dynamic>();
|
||||||
_id += 1;
|
_id += 1;
|
||||||
final id = _id;
|
final id = _id;
|
||||||
_registryTask(id, completer);
|
_registryTask(id, completer);
|
||||||
socket!.write(jsonrpc(method: method, id: id, params: params));
|
socket!.write(jsonrpc(method: method, id: id, params: params));
|
||||||
Timer(Duration(milliseconds: timeout), () {
|
var counter = 0;
|
||||||
if (!completer.isCompleted) {
|
Timer.periodic(Duration(milliseconds: timeout), (timer) {
|
||||||
|
if (!completer.isCompleted && counter > 5) {
|
||||||
|
timer.cancel();
|
||||||
completer.completeError(RequestFailedTimeoutException(method, id));
|
completer.completeError(RequestFailedTimeoutException(method, id));
|
||||||
|
} else if (completer.isCompleted) {
|
||||||
|
timer.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
counter++;
|
||||||
});
|
});
|
||||||
|
|
||||||
return completer.future;
|
return completer.future;
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
print(e.toString());
|
print(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue