@@ -412,31 +412,41 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
412
412
let mut ctx = self . execute_context ( turbo_tasks) ;
413
413
let mut task = ctx. task ( task_id, TaskDataCategory :: All ) ;
414
414
415
+ fn listen_to_done_event < B : BackingStorage > (
416
+ this : & TurboTasksBackendInner < B > ,
417
+ reader : Option < TaskId > ,
418
+ done_event : & Event ,
419
+ ) -> EventListener {
420
+ let reader_desc = reader. map ( |r| this. get_task_desc_fn ( r) ) ;
421
+ let listener = done_event. listen_with_note ( move || {
422
+ if let Some ( reader_desc) = reader_desc. as_ref ( ) {
423
+ format ! ( "try_read_task_output from {}" , reader_desc( ) )
424
+ } else {
425
+ "try_read_task_output (untracked)" . to_string ( )
426
+ }
427
+ } ) ;
428
+ listener
429
+ }
430
+
415
431
fn check_in_progress < B : BackingStorage > (
416
432
this : & TurboTasksBackendInner < B > ,
417
433
task : & impl TaskGuard ,
418
434
reader : Option < TaskId > ,
419
435
) -> Option < std:: result:: Result < std:: result:: Result < RawVc , EventListener > , anyhow:: Error > >
420
436
{
421
- if let Some ( in_progress) = get ! ( task, InProgress ) {
422
- match in_progress {
423
- InProgressState :: Scheduled { done_event, .. }
424
- | InProgressState :: InProgress ( box InProgressStateInner {
425
- done_event, ..
426
- } ) => {
427
- let reader_desc = reader. map ( |r| this. get_task_desc_fn ( r) ) ;
428
- let listener = done_event. listen_with_note ( move || {
429
- if let Some ( reader_desc) = reader_desc. as_ref ( ) {
430
- format ! ( "try_read_task_output from {}" , reader_desc( ) )
431
- } else {
432
- "try_read_task_output (untracked)" . to_string ( )
433
- }
434
- } ) ;
435
- return Some ( Ok ( Err ( listener) ) ) ;
436
- }
437
+ match get ! ( task, InProgress ) {
438
+ Some ( InProgressState :: Scheduled { done_event, .. } ) => {
439
+ Some ( Ok ( Err ( listen_to_done_event ( this, reader, done_event) ) ) )
440
+ }
441
+ Some ( InProgressState :: InProgress ( box InProgressStateInner {
442
+ marked_as_completed,
443
+ done_event,
444
+ ..
445
+ } ) ) if !* marked_as_completed => {
446
+ Some ( Ok ( Err ( listen_to_done_event ( this, reader, done_event) ) ) )
437
447
}
448
+ _ => None ,
438
449
}
439
- None
440
450
}
441
451
442
452
if self . should_track_children ( ) && matches ! ( consistency, ReadConsistency :: Strong ) {
@@ -1162,6 +1172,8 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
1162
1172
} ;
1163
1173
let & mut InProgressState :: InProgress ( box InProgressStateInner {
1164
1174
stale,
1175
+ ref mut marked_as_completed,
1176
+ ref done_event,
1165
1177
ref mut new_children,
1166
1178
..
1167
1179
} ) = in_progress
@@ -1194,6 +1206,14 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
1194
1206
) ;
1195
1207
return true ;
1196
1208
}
1209
+
1210
+ // mark the task as completed, so dependent tasks can continue working
1211
+ if !* marked_as_completed {
1212
+ * marked_as_completed = true ;
1213
+ done_event. notify ( usize:: MAX ) ;
1214
+ }
1215
+
1216
+ // take the children from the task to process them
1197
1217
let mut new_children = take ( new_children) ;
1198
1218
1199
1219
// TODO handle stateful
@@ -1452,8 +1472,6 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
1452
1472
1453
1473
drop ( task) ;
1454
1474
1455
- done_event. notify ( usize:: MAX ) ;
1456
-
1457
1475
if let Some ( data_update) = data_update {
1458
1476
AggregationUpdateQueue :: run ( data_update, & mut ctx) ;
1459
1477
}
@@ -1740,11 +1758,16 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
1740
1758
let mut task = ctx. task ( task, TaskDataCategory :: Data ) ;
1741
1759
if let Some ( InProgressState :: InProgress ( box InProgressStateInner {
1742
1760
marked_as_completed,
1761
+ done_event,
1743
1762
..
1744
1763
} ) ) = get_mut ! ( task, InProgress )
1745
1764
{
1746
1765
* marked_as_completed = true ;
1766
+ done_event. notify ( usize:: MAX ) ;
1747
1767
// TODO this should remove the dirty state (also check session_dependent)
1768
+ // but this would break some assumptions for strongly consistent reads.
1769
+ // Client tasks are not connected yet, so we wouldn't wait for them.
1770
+ // Maybe that's ok in cases where mark_finished() is used? Seems like it?
1748
1771
}
1749
1772
}
1750
1773
0 commit comments