From 326cd073b9ae08ed03b36efb5d025ee012565eaa Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Sun, 7 Oct 2018 18:27:10 +0300 Subject: [PATCH] Async data fetching --- lib/home_assistant.class.dart | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/home_assistant.class.dart b/lib/home_assistant.class.dart index 58b31fe..082d427 100644 --- a/lib/home_assistant.class.dart +++ b/lib/home_assistant.class.dart @@ -123,17 +123,18 @@ class HomeAssistant { return _connectionCompleter.future; } - _getData() { - _getConfig().then((result) { - _getStates().then((result) { - _getServices().then((result) { - _getUserInfo(); - _completeFetching(null); - }); - }); - }).catchError((e) { - _completeFetching(e); - }); + _getData() async { + List futures = []; + futures.add(_getStates()); + futures.add(_getConfig()); + futures.add(_getServices()); + //futures.add(_getUserInfo()); + try { + await Future.wait(futures); + _completeFetching(null); + } catch (error) { + _completeFetching(error); + } } void _completeFetching(error) {