mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Make PollingDeviceDiscovery start the initial poll faster. (#130755)
This will speed up the initial population of the device list.
This commit is contained in:
parent
86c8abf88b
commit
d1d78bc917
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user