From 5977458727b2b989347b2a12c88e5cf5716c45d4 Mon Sep 17 00:00:00 2001
From: "nweiz@google.com" <nweiz@google.com>
Date: Tue, 5 May 2015 22:54:36 +0000
Subject: [PATCH] Don't let the version solver starve the event queue.

R=rnystrom@google.com

Review URL: https://codereview.chromium.org//1127863002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@45543 260f80e4-7a28-3924-810f-c04153c831b5
---
 lib/src/solver/backtracking_solver.dart | 27 ++++++++++++-------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/lib/src/solver/backtracking_solver.dart b/lib/src/solver/backtracking_solver.dart
index 73dfd5c4..ecea2cd0 100644
--- a/lib/src/solver/backtracking_solver.dart
+++ b/lib/src/solver/backtracking_solver.dart
@@ -251,20 +251,19 @@ class BacktrackingSolver {
   /// If there are no more versions, continues to backtrack to previous
   /// selections, and so on. If there is nothing left to backtrack to,
   /// completes to the last failure that occurred.
-  Future<List<PackageId>> _traverseSolution() => resetStack(() {
-    return new Traverser(this).traverse().catchError((error) {
-      if (error is! SolveFailure) throw error;
-
-      return _backtrack(error).then((canTry) {
-        if (canTry) {
-          _attemptedSolutions++;
-          return _traverseSolution();
-        }
-
-        // All out of solutions, so fail.
-        throw error;
-      });
-    });
+  Future<List<PackageId>> _traverseSolution() => resetStack(() async {
+    // Avoid starving the event queue by waiting for a timer-level event.
+    await new Future(() {});
+
+    try {
+      return await new Traverser(this).traverse();
+    } on SolveFailure catch (error) {
+      // All out of solutions, so fail.
+      if (!(await _backtrack(error))) rethrow;
+
+      _attemptedSolutions++;
+      await _traverseSolution();
+    }
   });
 
   /// Backtracks from the current failed solution and determines the next
-- 
GitLab