@@ -77,16 +77,13 @@ pub trait TurboTasksCallApi: Sync + Send {
77
77
fn run_once (
78
78
& self ,
79
79
future : Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' static > > ,
80
- ) -> TaskId ;
80
+ ) -> Pin < Box < dyn Future < Output = Result < ( ) > > + Send > > ;
81
81
fn run_once_with_reason (
82
82
& self ,
83
83
reason : StaticOrArc < dyn InvalidationReason > ,
84
84
future : Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' static > > ,
85
- ) -> TaskId ;
86
- fn run_once_process (
87
- & self ,
88
- future : Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' static > > ,
89
- ) -> TaskId ;
85
+ ) -> Pin < Box < dyn Future < Output = Result < ( ) > > + Send > > ;
86
+ fn start_once_process ( & self , future : Pin < Box < dyn Future < Output = ( ) > + Send + ' static > > ) ;
90
87
}
91
88
92
89
/// A type-erased subset of [`TurboTasks`] stored inside a thread local when we're in a turbo task
@@ -490,7 +487,7 @@ impl<B: Backend + 'static> TurboTasks<B> {
490
487
/// Creates a new root task, that is only executed once.
491
488
/// Dependencies will not invalidate the task.
492
489
#[ track_caller]
493
- pub fn spawn_once_task < T , Fut > ( & self , future : Fut ) -> TaskId
490
+ fn spawn_once_task < T , Fut > ( & self , future : Fut ) -> TaskId
494
491
where
495
492
T : ?Sized ,
496
493
Fut : Future < Output = Result < Vc < T > > > + Send + ' static ,
@@ -530,6 +527,21 @@ impl<B: Backend + 'static> TurboTasks<B> {
530
527
Ok ( rx. await ?)
531
528
}
532
529
530
+ pub fn start_once_process ( & self , future : impl Future < Output = ( ) > + Send + ' static ) {
531
+ let this = self . pin ( ) ;
532
+ tokio:: spawn ( async move {
533
+ this. pin ( )
534
+ . run_once ( async move {
535
+ this. finish_foreground_job ( ) ;
536
+ future. await ;
537
+ this. begin_foreground_job ( ) ;
538
+ Ok ( ( ) )
539
+ } )
540
+ . await
541
+ . unwrap ( )
542
+ } ) ;
543
+ }
544
+
533
545
pub ( crate ) fn native_call (
534
546
& self ,
535
547
native_fn : & ' static NativeFunction ,
@@ -1107,41 +1119,28 @@ impl<B: Backend + 'static> TurboTasksCallApi for TurboTasks<B> {
1107
1119
fn run_once (
1108
1120
& self ,
1109
1121
future : Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' static > > ,
1110
- ) -> TaskId {
1111
- self . spawn_once_task ( async move {
1112
- future. await ?;
1113
- Ok ( Completion :: new ( ) )
1114
- } )
1122
+ ) -> Pin < Box < dyn Future < Output = Result < ( ) > > + Send > > {
1123
+ let this = self . pin ( ) ;
1124
+ Box :: pin ( async move { this. run_once ( future) . await } )
1115
1125
}
1116
1126
1117
1127
#[ track_caller]
1118
1128
fn run_once_with_reason (
1119
1129
& self ,
1120
1130
reason : StaticOrArc < dyn InvalidationReason > ,
1121
1131
future : Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' static > > ,
1122
- ) -> TaskId {
1132
+ ) -> Pin < Box < dyn Future < Output = Result < ( ) > > + Send > > {
1123
1133
{
1124
1134
let ( _, reason_set) = & mut * self . aggregated_update . lock ( ) . unwrap ( ) ;
1125
1135
reason_set. insert ( reason) ;
1126
1136
}
1127
- self . spawn_once_task ( async move {
1128
- future. await ?;
1129
- Ok ( Completion :: new ( ) )
1130
- } )
1137
+ let this = self . pin ( ) ;
1138
+ Box :: pin ( async move { this. run_once ( future) . await } )
1131
1139
}
1132
1140
1133
1141
#[ track_caller]
1134
- fn run_once_process (
1135
- & self ,
1136
- future : Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' static > > ,
1137
- ) -> TaskId {
1138
- let this = self . pin ( ) ;
1139
- self . spawn_once_task ( async move {
1140
- this. finish_foreground_job ( ) ;
1141
- future. await ?;
1142
- this. begin_foreground_job ( ) ;
1143
- Ok ( Completion :: new ( ) )
1144
- } )
1142
+ fn start_once_process ( & self , future : Pin < Box < dyn Future < Output = ( ) > + Send + ' static > > ) {
1143
+ self . start_once_process ( future)
1145
1144
}
1146
1145
}
1147
1146
@@ -1422,18 +1421,13 @@ pub async fn run_once<T: Send + 'static>(
1422
1421
) -> Result < T > {
1423
1422
let ( tx, rx) = tokio:: sync:: oneshot:: channel ( ) ;
1424
1423
1425
- let task_id = tt. run_once ( Box :: pin ( async move {
1424
+ tt. run_once ( Box :: pin ( async move {
1426
1425
let result = future. await ?;
1427
1426
tx. send ( result)
1428
1427
. map_err ( |_| anyhow ! ( "unable to send result" ) ) ?;
1429
1428
Ok ( ( ) )
1430
- } ) ) ;
1431
-
1432
- // INVALIDATION: A Once task will never invalidate, therefore we don't need to
1433
- // track a dependency
1434
- let raw_result = read_task_output_untracked ( & * tt, task_id, ReadConsistency :: Eventual ) . await ?;
1435
- let raw_future = raw_result. into_read ( ) . untracked ( ) ;
1436
- turbo_tasks_future_scope ( tt, ReadVcFuture :: < Completion > :: from ( raw_future) ) . await ?;
1429
+ } ) )
1430
+ . await ?;
1437
1431
1438
1432
Ok ( rx. await ?)
1439
1433
}
@@ -1445,21 +1439,16 @@ pub async fn run_once_with_reason<T: Send + 'static>(
1445
1439
) -> Result < T > {
1446
1440
let ( tx, rx) = tokio:: sync:: oneshot:: channel ( ) ;
1447
1441
1448
- let task_id = tt. run_once_with_reason (
1442
+ tt. run_once_with_reason (
1449
1443
( Arc :: new ( reason) as Arc < dyn InvalidationReason > ) . into ( ) ,
1450
1444
Box :: pin ( async move {
1451
1445
let result = future. await ?;
1452
1446
tx. send ( result)
1453
1447
. map_err ( |_| anyhow ! ( "unable to send result" ) ) ?;
1454
1448
Ok ( ( ) )
1455
1449
} ) ,
1456
- ) ;
1457
-
1458
- // INVALIDATION: A Once task will never invalidate, therefore we don't need to
1459
- // track a dependency
1460
- let raw_result = read_task_output_untracked ( & * tt, task_id, ReadConsistency :: Eventual ) . await ?;
1461
- let raw_future = raw_result. into_read ( ) . untracked ( ) ;
1462
- turbo_tasks_future_scope ( tt, ReadVcFuture :: < Completion > :: from ( raw_future) ) . await ?;
1450
+ )
1451
+ . await ?;
1463
1452
1464
1453
Ok ( rx. await ?)
1465
1454
}
0 commit comments