Skip to content

Commit bd9b7a0

Browse files
authored
refactor: rename async_run to background_run & sync_run to main_run (#8385)
1 parent 5dd500e commit bd9b7a0

File tree

9 files changed

+25
-27
lines changed

9 files changed

+25
-27
lines changed

crates/rspack_core/src/compiler/make/repair/add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Task<MakeTaskContext> for AddTask {
2121
fn get_task_type(&self) -> TaskType {
2222
TaskType::Sync
2323
}
24-
async fn sync_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
24+
async fn main_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
2525
let module_identifier = self.module.identifier();
2626
let artifact = &mut context.artifact;
2727
let module_graph =

crates/rspack_core/src/compiler/make/repair/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Task<MakeTaskContext> for BuildTask {
2626
fn get_task_type(&self) -> TaskType {
2727
TaskType::Async
2828
}
29-
async fn async_run(self: Box<Self>) -> TaskResult<MakeTaskContext> {
29+
async fn background_run(self: Box<Self>) -> TaskResult<MakeTaskContext> {
3030
let Self {
3131
compilation_id,
3232
compiler_options,
@@ -100,7 +100,7 @@ impl Task<MakeTaskContext> for BuildResultTask {
100100
fn get_task_type(&self) -> TaskType {
101101
TaskType::Sync
102102
}
103-
async fn sync_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
103+
async fn main_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
104104
let BuildResultTask {
105105
mut module,
106106
build_result,

crates/rspack_core/src/compiler/make/repair/factorize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Task<MakeTaskContext> for FactorizeTask {
3333
fn get_task_type(&self) -> TaskType {
3434
TaskType::Async
3535
}
36-
async fn async_run(self: Box<Self>) -> TaskResult<MakeTaskContext> {
36+
async fn background_run(self: Box<Self>) -> TaskResult<MakeTaskContext> {
3737
if let Some(current_profile) = &self.current_profile {
3838
current_profile.mark_factory_start();
3939
}
@@ -204,7 +204,7 @@ impl Task<MakeTaskContext> for FactorizeResultTask {
204204
fn get_task_type(&self) -> TaskType {
205205
TaskType::Sync
206206
}
207-
async fn sync_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
207+
async fn main_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
208208
let FactorizeResultTask {
209209
original_module_identifier,
210210
factory_result,

crates/rspack_core/src/compiler/make/repair/process_dependencies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl Task<MakeTaskContext> for ProcessDependenciesTask {
1919
TaskType::Sync
2020
}
2121

22-
async fn sync_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
22+
async fn main_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
2323
let Self {
2424
original_module_identifier,
2525
dependencies,

crates/rspack_core/src/compiler/module_executor/ctrl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Task<MakeTaskContext> for CtrlTask {
104104
TaskType::Async
105105
}
106106

107-
async fn async_run(mut self: Box<Self>) -> TaskResult<MakeTaskContext> {
107+
async fn background_run(mut self: Box<Self>) -> TaskResult<MakeTaskContext> {
108108
while let Some(event) = self.event_receiver.recv().await {
109109
tracing::info!("CtrlTask async receive {:?}", event);
110110
match event {
@@ -202,7 +202,7 @@ impl Task<MakeTaskContext> for FinishModuleTask {
202202
TaskType::Sync
203203
}
204204

205-
async fn sync_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
205+
async fn main_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
206206
let Self {
207207
mut ctrl_task,
208208
module_identifier,

crates/rspack_core/src/compiler/module_executor/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Task<MakeTaskContext> for EntryTask {
1515
TaskType::Sync
1616
}
1717

18-
async fn sync_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
18+
async fn main_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
1919
let Self { dep, layer } = *self;
2020
let mut module_graph =
2121
MakeTaskContext::get_module_graph_mut(&mut context.artifact.module_graph_partial);

crates/rspack_core/src/compiler/module_executor/execute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Task<MakeTaskContext> for ExecuteTask {
6060
TaskType::Sync
6161
}
6262

63-
async fn sync_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
63+
async fn main_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
6464
let Self {
6565
entry_dep_id,
6666
layer,

crates/rspack_core/src/compiler/module_executor/overwrite.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Task<MakeTaskContext> for OverwriteTask {
2121
self.origin_task.get_task_type()
2222
}
2323

24-
async fn sync_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
24+
async fn main_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
2525
let Self {
2626
origin_task,
2727
event_sender,
@@ -32,7 +32,7 @@ impl Task<MakeTaskContext> for OverwriteTask {
3232
.downcast_ref::<ProcessDependenciesTask>()
3333
{
3434
let original_module_identifier = process_dependencies_task.original_module_identifier;
35-
let res = origin_task.sync_run(context).await?;
35+
let res = origin_task.main_run(context).await?;
3636
event_sender
3737
.send(Event::FinishModule(original_module_identifier, res.len()))
3838
.expect("should success");
@@ -44,7 +44,7 @@ impl Task<MakeTaskContext> for OverwriteTask {
4444
{
4545
let dep_id = *factorize_result_task.dependencies[0].id();
4646
let original_module_identifier = factorize_result_task.original_module_identifier;
47-
let res = origin_task.sync_run(context).await?;
47+
let res = origin_task.main_run(context).await?;
4848
if res.is_empty() {
4949
event_sender
5050
.send(Event::FinishDeps(original_module_identifier, dep_id, None))
@@ -58,7 +58,7 @@ impl Task<MakeTaskContext> for OverwriteTask {
5858
let original_module_identifier = add_task.original_module_identifier;
5959
let target_module_identifier = add_task.module.identifier();
6060

61-
let res = origin_task.sync_run(context).await?;
61+
let res = origin_task.main_run(context).await?;
6262
if res.is_empty() {
6363
event_sender
6464
.send(Event::FinishDeps(
@@ -76,10 +76,10 @@ impl Task<MakeTaskContext> for OverwriteTask {
7676
}
7777

7878
// other task
79-
origin_task.sync_run(context).await
79+
origin_task.main_run(context).await
8080
}
8181

82-
async fn async_run(self: Box<Self>) -> TaskResult<MakeTaskContext> {
83-
self.origin_task.async_run().await
82+
async fn background_run(self: Box<Self>) -> TaskResult<MakeTaskContext> {
83+
self.origin_task.background_run().await
8484
}
8585
}

crates/rspack_core/src/utils/task_loop.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ pub trait Task<Ctx>: Debug + Send + Any + AsAny {
3636
/// Return `TaskType::Async` will run `self::async_run`
3737
fn get_task_type(&self) -> TaskType;
3838

39-
/// Sync task process
40-
///
41-
/// The context is shared with all tasks
42-
async fn sync_run(self: Box<Self>, _context: &mut Ctx) -> TaskResult<Ctx> {
39+
/// can be running in main thread
40+
async fn main_run(self: Box<Self>, _context: &mut Ctx) -> TaskResult<Ctx> {
4341
unreachable!();
4442
}
4543

46-
/// Async task process
47-
async fn async_run(self: Box<Self>) -> TaskResult<Ctx> {
44+
/// can be running in background thread
45+
async fn background_run(self: Box<Self>) -> TaskResult<Ctx> {
4846
unreachable!();
4947
}
5048
}
@@ -84,15 +82,15 @@ pub async fn run_task_loop_with_event<Ctx: 'static>(
8482
let is_expected_shutdown = is_expected_shutdown.clone();
8583
active_task_count += 1;
8684
tokio::spawn(async move {
87-
let r = task.async_run().await;
85+
let r = task.background_run().await;
8886
if !is_expected_shutdown.load(Ordering::Relaxed) {
8987
tx.send(r).expect("failed to send error message");
9088
}
9189
});
9290
}
9391
TaskType::Sync => {
9492
// merge sync task result directly
95-
match task.sync_run(ctx).await {
93+
match task.main_run(ctx).await {
9694
Ok(r) => queue.extend(r),
9795
Err(e) => {
9896
is_expected_shutdown.store(true, Ordering::Relaxed);
@@ -151,7 +149,7 @@ mod test {
151149
fn get_task_type(&self) -> TaskType {
152150
TaskType::Sync
153151
}
154-
async fn sync_run(self: Box<Self>, context: &mut Context) -> TaskResult<Context> {
152+
async fn main_run(self: Box<Self>, context: &mut Context) -> TaskResult<Context> {
155153
if context.sync_return_error {
156154
return Err(miette!("throw sync error"));
157155
}
@@ -177,7 +175,7 @@ mod test {
177175
fn get_task_type(&self) -> TaskType {
178176
TaskType::Async
179177
}
180-
async fn async_run(self: Box<Self>) -> TaskResult<Context> {
178+
async fn background_run(self: Box<Self>) -> TaskResult<Context> {
181179
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
182180
if self.async_return_error {
183181
Err(miette!("throw async error"))

0 commit comments

Comments
 (0)