File tree Expand file tree Collapse file tree 2 files changed +21
-18
lines changed Expand file tree Collapse file tree 2 files changed +21
-18
lines changed Original file line number Diff line number Diff line change @@ -553,23 +553,7 @@ impl Context {
553
553
554
554
if self . scheduler . is_running ( ) . await {
555
555
self . scheduler . maybe_network ( ) . await ;
556
-
557
- // Wait until fetching is finished.
558
- // Ideally we could wait for connectivity change events,
559
- // but sleep loop is good enough.
560
-
561
- // First 100 ms sleep in chunks of 10 ms.
562
- for _ in 0 ..10 {
563
- if self . all_work_done ( ) . await {
564
- break ;
565
- }
566
- tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) . await ;
567
- }
568
-
569
- // If we are not finished in 100 ms, keep waking up every 100 ms.
570
- while !self . all_work_done ( ) . await {
571
- tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
572
- }
556
+ self . wait_for_all_work_done ( ) . await ;
573
557
} else {
574
558
// Pause the scheduler to ensure another connection does not start
575
559
// while we are fetching on a dedicated connection.
Original file line number Diff line number Diff line change @@ -535,7 +535,7 @@ impl Context {
535
535
}
536
536
537
537
/// Returns true if all background work is done.
538
- pub async fn all_work_done ( & self ) -> bool {
538
+ async fn all_work_done ( & self ) -> bool {
539
539
let lock = self . scheduler . inner . read ( ) . await ;
540
540
let stores: Vec < _ > = match * lock {
541
541
InnerSchedulerState :: Started ( ref sched) => sched
@@ -555,4 +555,23 @@ impl Context {
555
555
}
556
556
true
557
557
}
558
+
559
+ /// Waits until background work is finished.
560
+ pub async fn wait_for_all_work_done ( & self ) {
561
+ // Ideally we could wait for connectivity change events,
562
+ // but sleep loop is good enough.
563
+
564
+ // First 100 ms sleep in chunks of 10 ms.
565
+ for _ in 0 ..10 {
566
+ if self . all_work_done ( ) . await {
567
+ break ;
568
+ }
569
+ tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) . await ;
570
+ }
571
+
572
+ // If we are not finished in 100 ms, keep waking up every 100 ms.
573
+ while !self . all_work_done ( ) . await {
574
+ tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
575
+ }
576
+ }
558
577
}
You can’t perform that action at this time.
0 commit comments