Make PollingDeviceDiscovery start the initial poll faster. (#130755)

This will speed up the initial population of the device list.
This commit is contained in:
Lau Ching Jun
2023-07-19 22:01:24 -07:00
committed by GitHub
parent 86c8abf88b
commit d1d78bc917
3 changed files with 5 additions and 8 deletions

View File

@@ -504,12 +504,13 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery {
if (_timer == null) {
deviceNotifier ??= ItemListNotifier<Device>();
// Make initial population the default, fast polling timeout.
_timer = _initTimer(null);
_timer = _initTimer(null, initialCall: true);
}
}
Timer _initTimer(Duration? pollingTimeout) {
return Timer(_pollingInterval, () async {
Timer _initTimer(Duration? pollingTimeout, {bool initialCall = false}) {
// Poll for devices immediately on the initial call for faster initial population.
return Timer(initialCall ? Duration.zero : _pollingInterval, () async {
try {
final List<Device> devices = await pollingGetDevices(timeout: pollingTimeout);
deviceNotifier!.updateWithNewList(devices);