Unverified Commit d1d78bc9 authored by Lau Ching Jun's avatar Lau Ching Jun Committed by GitHub

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

This will speed up the initial population of the device list.
parent 86c8abf8
...@@ -504,12 +504,13 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery { ...@@ -504,12 +504,13 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery {
if (_timer == null) { if (_timer == null) {
deviceNotifier ??= ItemListNotifier<Device>(); deviceNotifier ??= ItemListNotifier<Device>();
// Make initial population the default, fast polling timeout. // Make initial population the default, fast polling timeout.
_timer = _initTimer(null); _timer = _initTimer(null, initialCall: true);
} }
} }
Timer _initTimer(Duration? pollingTimeout) { Timer _initTimer(Duration? pollingTimeout, {bool initialCall = false}) {
return Timer(_pollingInterval, () async { // Poll for devices immediately on the initial call for faster initial population.
return Timer(initialCall ? Duration.zero : _pollingInterval, () async {
try { try {
final List<Device> devices = await pollingGetDevices(timeout: pollingTimeout); final List<Device> devices = await pollingGetDevices(timeout: pollingTimeout);
deviceNotifier!.updateWithNewList(devices); deviceNotifier!.updateWithNewList(devices);
......
...@@ -234,7 +234,6 @@ void main() { ...@@ -234,7 +234,6 @@ void main() {
FakeAsync().run((FakeAsync time) { FakeAsync().run((FakeAsync time) {
final FakePollingDeviceDiscovery pollingDeviceDiscovery = FakePollingDeviceDiscovery(); final FakePollingDeviceDiscovery pollingDeviceDiscovery = FakePollingDeviceDiscovery();
pollingDeviceDiscovery.startPolling(); pollingDeviceDiscovery.startPolling();
time.elapse(const Duration(milliseconds: 4001));
// First check should use the default polling timeout // First check should use the default polling timeout
// to quickly populate the list. // to quickly populate the list.
......
...@@ -397,10 +397,7 @@ void main() { ...@@ -397,10 +397,7 @@ void main() {
expect(devicesAdded[0].id, fakeDevice['id']); expect(devicesAdded[0].id, fakeDevice['id']);
expect(devicesAdded[1].id, fakeDevice2['id']); expect(devicesAdded[1].id, fakeDevice2['id']);
}); });
// Explicit timeout is needed because the default timeout is 2s, but `startPolling` waits for });
// 4s before making its first poll.
// TODO(chingjun): Remove the timeout.
}, timeout: const Timeout(Duration(seconds: 6)));
group('ProxiedDartDevelopmentService', () { group('ProxiedDartDevelopmentService', () {
testWithoutContext('forwards start and shutdown to remote', () async { testWithoutContext('forwards start and shutdown to remote', () async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment