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 {
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);
......
......@@ -234,7 +234,6 @@ void main() {
FakeAsync().run((FakeAsync time) {
final FakePollingDeviceDiscovery pollingDeviceDiscovery = FakePollingDeviceDiscovery();
pollingDeviceDiscovery.startPolling();
time.elapse(const Duration(milliseconds: 4001));
// First check should use the default polling timeout
// to quickly populate the list.
......
......@@ -397,10 +397,7 @@ void main() {
expect(devicesAdded[0].id, fakeDevice['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', () {
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