Implement fetch timer with 30 timeout along with connection timer
This commit is contained in:
parent
b14b248f2f
commit
41297150c2
@ -22,6 +22,7 @@ class HomeAssistant {
|
|||||||
Completer _configCompleter;
|
Completer _configCompleter;
|
||||||
Completer _connectionCompleter;
|
Completer _connectionCompleter;
|
||||||
Timer _connectionTimer;
|
Timer _connectionTimer;
|
||||||
|
Timer _fetchTimer;
|
||||||
|
|
||||||
String get locationName => _instanceConfig["location_name"] ?? "";
|
String get locationName => _instanceConfig["location_name"] ?? "";
|
||||||
int get viewsCount => _entities.viewList.length ?? 0;
|
int get viewsCount => _entities.viewList.length ?? 0;
|
||||||
@ -42,6 +43,10 @@ class HomeAssistant {
|
|||||||
TheLogger.log("Warning","Previous fetch is not complited");
|
TheLogger.log("Warning","Previous fetch is not complited");
|
||||||
} else {
|
} else {
|
||||||
_fetchCompleter = new Completer();
|
_fetchCompleter = new Completer();
|
||||||
|
_fetchTimer = Timer(Duration(seconds: 30), () {
|
||||||
|
closeConnection();
|
||||||
|
_finishFetching({"errorCode" : 9,"errorMessage": "Connection timeout or connection issues"});
|
||||||
|
});
|
||||||
_reConnectSocket().then((r) {
|
_reConnectSocket().then((r) {
|
||||||
_getData();
|
_getData();
|
||||||
}).catchError((e) {
|
}).catchError((e) {
|
||||||
@ -100,9 +105,13 @@ class HomeAssistant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _finishFetching(error) {
|
void _finishFetching(error) {
|
||||||
|
_fetchTimer.cancel();
|
||||||
|
_finishConnecting(error);
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
|
if (!_fetchCompleter.isCompleted)
|
||||||
_fetchCompleter.completeError(error);
|
_fetchCompleter.completeError(error);
|
||||||
} else {
|
} else {
|
||||||
|
if (!_fetchCompleter.isCompleted)
|
||||||
_fetchCompleter.complete();
|
_fetchCompleter.complete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,6 +119,7 @@ class HomeAssistant {
|
|||||||
void _finishConnecting(error) {
|
void _finishConnecting(error) {
|
||||||
_connectionTimer.cancel();
|
_connectionTimer.cancel();
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
|
if (!_connectionCompleter.isCompleted)
|
||||||
_connectionCompleter.completeError(error);
|
_connectionCompleter.completeError(error);
|
||||||
} else {
|
} else {
|
||||||
if (!_connectionCompleter.isCompleted)
|
if (!_connectionCompleter.isCompleted)
|
||||||
|
@ -505,6 +505,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
String message = _lastErrorMessage;
|
String message = _lastErrorMessage;
|
||||||
SnackBarAction action;
|
SnackBarAction action;
|
||||||
switch (_errorCodeToBeShown) {
|
switch (_errorCodeToBeShown) {
|
||||||
|
case 9:
|
||||||
case 1: {
|
case 1: {
|
||||||
action = SnackBarAction(
|
action = SnackBarAction(
|
||||||
label: "Retry",
|
label: "Retry",
|
||||||
|
Reference in New Issue
Block a user