mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Avoid concurrent device polling in daemon; add timeout (#11184)
Apply a 30 second timeout to Android/iOS device polling. If there's a device poll already in progress, skip polling for new devices; wait for the first request to return/timeout.
This commit is contained in:
parent
ae90581124
commit
0adb39ae9b
@ -111,7 +111,8 @@ abstract class DeviceDiscovery {
|
||||
abstract class PollingDeviceDiscovery extends DeviceDiscovery {
|
||||
PollingDeviceDiscovery(this.name);
|
||||
|
||||
static const Duration _pollingDuration = const Duration(seconds: 4);
|
||||
static const Duration _pollingInterval = const Duration(seconds: 4);
|
||||
static const Duration _pollingTimeout = const Duration(seconds: 30);
|
||||
|
||||
final String name;
|
||||
ItemListNotifier<Device> _items;
|
||||
@ -122,8 +123,21 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery {
|
||||
void startPolling() {
|
||||
if (_timer == null) {
|
||||
_items ??= new ItemListNotifier<Device>();
|
||||
_timer = new Timer.periodic(_pollingDuration, (Timer timer) async {
|
||||
_items.updateWithNewList(await pollingGetDevices());
|
||||
bool _fetchingDevices = false;
|
||||
_timer = new Timer.periodic(_pollingInterval, (Timer timer) async {
|
||||
if (_fetchingDevices) {
|
||||
printTrace('Skipping device poll: already in progress');
|
||||
return;
|
||||
}
|
||||
_fetchingDevices = true;
|
||||
try {
|
||||
final List<Device> devices = await pollingGetDevices().timeout(_pollingTimeout);
|
||||
_items.updateWithNewList(devices);
|
||||
} on TimeoutException {
|
||||
printTrace('Device poll timed out.');
|
||||
} finally {
|
||||
_fetchingDevices = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user