@@ -79,16 +79,13 @@ pub trait TurboTasksCallApi: Sync + Send {
79
79
fn run_once (
80
80
& self ,
81
81
future : Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' static > > ,
82
- ) -> TaskId ;
82
+ ) -> Pin < Box < dyn Future < Output = Result < ( ) > > + Send > > ;
83
83
fn run_once_with_reason (
84
84
& self ,
85
85
reason : StaticOrArc < dyn InvalidationReason > ,
86
86
future : Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' static > > ,
87
- ) -> TaskId ;
88
- fn run_once_process (
89
- & self ,
90
- future : Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' static > > ,
91
- ) -> TaskId ;
87
+ ) -> Pin < Box < dyn Future < Output = Result < ( ) > > + Send > > ;
88
+ fn start_once_process ( & self , future : Pin < Box < dyn Future < Output = ( ) > + Send + ' static > > ) ;
92
89
}
93
90
94
91
/// A type-erased subset of [`TurboTasks`] stored inside a thread local when we're in a turbo task
@@ -558,7 +555,7 @@ impl<B: Backend + 'static> TurboTasks<B> {
558
555
/// Creates a new root task, that is only executed once.
559
556
/// Dependencies will not invalidate the task.
560
557
#[ track_caller]
561
- pub fn spawn_once_task < T , Fut > ( & self , future : Fut ) -> TaskId
558
+ fn spawn_once_task < T , Fut > ( & self , future : Fut ) -> TaskId
562
559
where
563
560
T : ?Sized ,
564
561
Fut : Future < Output = Result < Vc < T > > > + Send + ' static ,
@@ -598,6 +595,21 @@ impl<B: Backend + 'static> TurboTasks<B> {
598
595
Ok ( rx. await ?)
599
596
}
600
597
598
+ pub fn start_once_process ( & self , future : impl Future < Output = ( ) > + Send + ' static ) {
599
+ let this = self . pin ( ) ;
600
+ tokio:: spawn ( async move {
601
+ this. pin ( )
602
+ . run_once ( async move {
603
+ this. finish_foreground_job ( ) ;
604
+ future. await ;
605
+ this. begin_foreground_job ( ) ;
606
+ Ok ( ( ) )
607
+ } )
608
+ . await
609
+ . unwrap ( )
610
+ } ) ;
611
+ }
612
+
601
613
pub ( crate ) fn native_call (
602
614
& self ,
603
615
native_fn : & ' static NativeFunction ,
@@ -1185,41 +1197,28 @@ impl<B: Backend + 'static> TurboTasksCallApi for TurboTasks<B> {
1185
1197
fn run_once (
1186
1198
& self ,
1187
1199
future : Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' static > > ,
1188
- ) -> TaskId {
1189
- self . spawn_once_task ( async move {
1190
- future. await ?;
1191
- Ok ( Completion :: new ( ) )
1192
- } )
1200
+ ) -> Pin < Box < dyn Future < Output = Result < ( ) > > + Send > > {
1201
+ let this = self . pin ( ) ;
1202
+ Box :: pin ( async move { this. run_once ( future) . await } )
1193
1203
}
1194
1204
1195
1205
#[ track_caller]
1196
1206
fn run_once_with_reason (
1197
1207
& self ,
1198
1208
reason : StaticOrArc < dyn InvalidationReason > ,
1199
1209
future : Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' static > > ,
1200
- ) -> TaskId {
1210
+ ) -> Pin < Box < dyn Future < Output = Result < ( ) > > + Send > > {
1201
1211
{
1202
1212
let ( _, reason_set) = & mut * self . aggregated_update . lock ( ) . unwrap ( ) ;
1203
1213
reason_set. insert ( reason) ;
1204
1214
}
1205
- self . spawn_once_task ( async move {
1206
- future. await ?;
1207
- Ok ( Completion :: new ( ) )
1208
- } )
1215
+ let this = self . pin ( ) ;
1216
+ Box :: pin ( async move { this. run_once ( future) . await } )
1209
1217
}
1210
1218
1211
1219
#[ track_caller]
1212
- fn run_once_process (
1213
- & self ,
1214
- future : Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' static > > ,
1215
- ) -> TaskId {
1216
- let this = self . pin ( ) ;
1217
- self . spawn_once_task ( async move {
1218
- this. finish_foreground_job ( ) ;
1219
- future. await ?;
1220
- this. begin_foreground_job ( ) ;
1221
- Ok ( Completion :: new ( ) )
1222
- } )
1220
+ fn start_once_process ( & self , future : Pin < Box < dyn Future < Output = ( ) > + Send + ' static > > ) {
1221
+ self . start_once_process ( future)
1223
1222
}
1224
1223
}
1225
1224
@@ -1555,18 +1554,13 @@ pub async fn run_once<T: Send + 'static>(
1555
1554
) -> Result < T > {
1556
1555
let ( tx, rx) = tokio:: sync:: oneshot:: channel ( ) ;
1557
1556
1558
- let task_id = tt. run_once ( Box :: pin ( async move {
1557
+ tt. run_once ( Box :: pin ( async move {
1559
1558
let result = future. await ?;
1560
1559
tx. send ( result)
1561
1560
. map_err ( |_| anyhow ! ( "unable to send result" ) ) ?;
1562
1561
Ok ( ( ) )
1563
- } ) ) ;
1564
-
1565
- // INVALIDATION: A Once task will never invalidate, therefore we don't need to
1566
- // track a dependency
1567
- let raw_result = read_task_output_untracked ( & * tt, task_id, ReadConsistency :: Eventual ) . await ?;
1568
- let raw_future = raw_result. into_read ( ) . untracked ( ) ;
1569
- turbo_tasks_future_scope ( tt, ReadVcFuture :: < Completion > :: from ( raw_future) ) . await ?;
1562
+ } ) )
1563
+ . await ?;
1570
1564
1571
1565
Ok ( rx. await ?)
1572
1566
}
@@ -1578,21 +1572,16 @@ pub async fn run_once_with_reason<T: Send + 'static>(
1578
1572
) -> Result < T > {
1579
1573
let ( tx, rx) = tokio:: sync:: oneshot:: channel ( ) ;
1580
1574
1581
- let task_id = tt. run_once_with_reason (
1575
+ tt. run_once_with_reason (
1582
1576
( Arc :: new ( reason) as Arc < dyn InvalidationReason > ) . into ( ) ,
1583
1577
Box :: pin ( async move {
1584
1578
let result = future. await ?;
1585
1579
tx. send ( result)
1586
1580
. map_err ( |_| anyhow ! ( "unable to send result" ) ) ?;
1587
1581
Ok ( ( ) )
1588
1582
} ) ,
1589
- ) ;
1590
-
1591
- // INVALIDATION: A Once task will never invalidate, therefore we don't need to
1592
- // track a dependency
1593
- let raw_result = read_task_output_untracked ( & * tt, task_id, ReadConsistency :: Eventual ) . await ?;
1594
- let raw_future = raw_result. into_read ( ) . untracked ( ) ;
1595
- turbo_tasks_future_scope ( tt, ReadVcFuture :: < Completion > :: from ( raw_future) ) . await ?;
1583
+ )
1584
+ . await ?;
1596
1585
1597
1586
Ok ( rx. await ?)
1598
1587
}
0 commit comments