[driver] fix a race in finder logic (#3444)

This commit is contained in:
Yegor 2016-04-20 15:26:09 -07:00
parent fffbf6e97b
commit 7fe7de3f12

View File

@ -120,7 +120,14 @@ class FlutterDriverExtension {
Future<Health> getHealth(GetHealth command) async => new Health(HealthStatus.ok);
/// Runs [locator] repeatedly until it finds an [Element] or times out.
Future<Element> _waitForElement(String descriptionGetter(), Element locator()) {
Future<Element> _waitForElement(String descriptionGetter(), Element locator()) async {
// Short-circuit if the element is already on the UI
Element element = locator();
if (element != null) {
return element;
}
// No element yet, so we retry on frames rendered in the future.
Completer<Element> completer = new Completer<Element>();
StreamSubscription<Duration> subscription;