Skip to content

Commit 6c14ae5

Browse files
committed
chore: remove useless async-scoped
1 parent 9a51f98 commit 6c14ae5

File tree

7 files changed

+74
-150
lines changed

7 files changed

+74
-150
lines changed

Cargo.lock

Lines changed: 0 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ single_match = "allow"
6969
[workspace.dependencies]
7070
anyhow = "1.0.82"
7171
ariadne = "0.4.0"
72-
async-scoped = { version = "0.9.0" }
7372
async-trait = "0.1.80"
7473
codspeed-criterion-compat = "2.4"
7574
dashmap = "5.5.3"

crates/rolldown/src/stages/bundle_stage/mod.rs

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
use std::sync::Arc;
22

3+
use futures::future::try_join_all;
4+
use rolldown_common::{
5+
ChunkKind, FileNameRenderOptions, Output, OutputAsset, OutputChunk, SourceMapType,
6+
};
7+
use rolldown_error::BuildError;
8+
use rolldown_plugin::SharedPluginDriver;
9+
use rustc_hash::FxHashSet;
10+
311
use crate::{
412
chunk::ChunkRenderReturn,
513
chunk_graph::ChunkGraph,
@@ -9,14 +17,7 @@ use crate::{
917
utils::{finalize_normal_module, is_in_rust_test_mode, render_chunks::render_chunks},
1018
SharedOptions,
1119
};
12-
use rolldown_utils::block_on_spawn_all;
1320

14-
use rolldown_common::{
15-
ChunkKind, FileNameRenderOptions, Output, OutputAsset, OutputChunk, SourceMapType,
16-
};
17-
use rolldown_error::BuildError;
18-
use rolldown_plugin::SharedPluginDriver;
19-
use rustc_hash::FxHashSet;
2021
mod code_splitting;
2122
mod compute_cross_chunk_links;
2223

@@ -80,54 +81,51 @@ impl<'a> BundleStage<'a> {
8081
});
8182
tracing::info!("finalizing modules");
8283

83-
let chunks = block_on_spawn_all(
84+
let chunks = try_join_all(
8485
chunk_graph
8586
.chunks
8687
.iter()
8788
.map(|c| async { c.render(self.options, self.link_output, &chunk_graph).await }),
8889
)
89-
.into_iter()
90-
.collect::<Result<Vec<_>, _>>()?;
90+
.await?;
9191

9292
let mut assets = vec![];
9393

94-
render_chunks(self.plugin_driver, chunks).await?.into_iter().try_for_each(
95-
|chunk| -> Result<(), BuildError> {
96-
let ChunkRenderReturn { mut map, rendered_chunk, mut code } = chunk;
97-
if let Some(map) = map.as_mut() {
98-
map.set_file(&rendered_chunk.file_name);
99-
match self.options.sourcemap {
100-
SourceMapType::File => {
101-
let map_file_name = format!("{}.map", rendered_chunk.file_name);
102-
assets.push(Output::Asset(Arc::new(OutputAsset {
103-
file_name: map_file_name.clone(),
104-
source: map.to_json_string().map_err(BuildError::sourcemap_error)?,
105-
})));
106-
code.push_str(&format!("\n//# sourceMappingURL={map_file_name}"));
107-
}
108-
SourceMapType::Inline => {
109-
let data_url = map.to_data_url().map_err(BuildError::sourcemap_error)?;
110-
code.push_str(&format!("\n//# sourceMappingURL={data_url}"));
111-
}
112-
SourceMapType::Hidden => {}
94+
for ChunkRenderReturn { mut map, rendered_chunk, mut code } in
95+
render_chunks(self.plugin_driver, chunks).await?
96+
{
97+
if let Some(map) = map.as_mut() {
98+
map.set_file(&rendered_chunk.file_name);
99+
match self.options.sourcemap {
100+
SourceMapType::File => {
101+
let map_file_name = format!("{}.map", rendered_chunk.file_name);
102+
assets.push(Output::Asset(Arc::new(OutputAsset {
103+
file_name: map_file_name.clone(),
104+
source: map.to_json_string().map_err(BuildError::sourcemap_error)?,
105+
})));
106+
code.push_str(&format!("\n//# sourceMappingURL={map_file_name}"));
107+
}
108+
SourceMapType::Inline => {
109+
let data_url = map.to_data_url().map_err(BuildError::sourcemap_error)?;
110+
code.push_str(&format!("\n//# sourceMappingURL={data_url}"));
113111
}
112+
SourceMapType::Hidden => {}
114113
}
115-
let sourcemap_file_name = map.as_ref().map(|_| format!("{}.map", rendered_chunk.file_name));
116-
assets.push(Output::Chunk(Arc::new(OutputChunk {
117-
file_name: rendered_chunk.file_name,
118-
code,
119-
is_entry: rendered_chunk.is_entry,
120-
is_dynamic_entry: rendered_chunk.is_dynamic_entry,
121-
facade_module_id: rendered_chunk.facade_module_id,
122-
modules: rendered_chunk.modules,
123-
exports: rendered_chunk.exports,
124-
module_ids: rendered_chunk.module_ids,
125-
map,
126-
sourcemap_file_name,
127-
})));
128-
Ok(())
129-
},
130-
)?;
114+
}
115+
let sourcemap_file_name = map.as_ref().map(|_| format!("{}.map", rendered_chunk.file_name));
116+
assets.push(Output::Chunk(Arc::new(OutputChunk {
117+
file_name: rendered_chunk.file_name,
118+
code,
119+
is_entry: rendered_chunk.is_entry,
120+
is_dynamic_entry: rendered_chunk.is_dynamic_entry,
121+
facade_module_id: rendered_chunk.facade_module_id,
122+
modules: rendered_chunk.modules,
123+
exports: rendered_chunk.exports,
124+
module_ids: rendered_chunk.module_ids,
125+
map,
126+
sourcemap_file_name,
127+
})));
128+
}
131129

132130
tracing::info!("rendered chunks");
133131

crates/rolldown/src/stages/scan_stage.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::sync::Arc;
22

3+
use futures::future::join_all;
34
use index_vec::IndexVec;
45
use rolldown_common::{EntryPoint, ImportKind, IntoBatchedResult, NormalModuleId};
56
use rolldown_error::BuildError;
67
use rolldown_fs::OsFileSystem;
78
use rolldown_oxc_utils::OxcAst;
89
use rolldown_plugin::{HookResolveIdExtraOptions, SharedPluginDriver};
9-
use rolldown_utils::block_on_spawn_all;
1010

1111
use crate::{
1212
error::BatchedResult,
@@ -60,7 +60,7 @@ impl ScanStage {
6060

6161
module_loader.try_spawn_runtime_module_task();
6262

63-
let user_entries = self.resolve_user_defined_entries()?;
63+
let user_entries = self.resolve_user_defined_entries().await?;
6464

6565
let ModuleLoaderOutput { module_table, entry_points, symbols, runtime, warnings, ast_table } =
6666
module_loader.fetch_all_modules(user_entries).await?;
@@ -72,34 +72,34 @@ impl ScanStage {
7272

7373
/// Resolve `InputOptions.input`
7474
#[tracing::instrument(skip_all)]
75-
fn resolve_user_defined_entries(
75+
async fn resolve_user_defined_entries(
7676
&self,
7777
) -> BatchedResult<Vec<(Option<String>, ResolvedRequestInfo)>> {
7878
let resolver = &self.resolver;
7979
let plugin_driver = &self.plugin_driver;
8080

81-
let resolved_ids =
82-
block_on_spawn_all(self.input_options.input.iter().map(|input_item| async move {
83-
let specifier = &input_item.import;
84-
match resolve_id(
85-
resolver,
86-
plugin_driver,
87-
specifier,
88-
None,
89-
HookResolveIdExtraOptions { is_entry: true, kind: ImportKind::Import },
90-
false,
91-
)
92-
.await
93-
{
94-
Ok(info) => {
95-
if info.is_external {
96-
return Err(BuildError::entry_cannot_be_external(&*info.path.path));
97-
}
98-
Ok((input_item.name.clone(), info))
81+
let resolved_ids = join_all(self.input_options.input.iter().map(|input_item| async move {
82+
let specifier = &input_item.import;
83+
match resolve_id(
84+
resolver,
85+
plugin_driver,
86+
specifier,
87+
None,
88+
HookResolveIdExtraOptions { is_entry: true, kind: ImportKind::Import },
89+
false,
90+
)
91+
.await
92+
{
93+
Ok(info) => {
94+
if info.is_external {
95+
return Err(BuildError::entry_cannot_be_external(&*info.path.path));
9996
}
100-
Err(e) => Err(e),
97+
Ok((input_item.name.clone(), info))
10198
}
102-
}));
99+
Err(e) => Err(e),
100+
}
101+
}))
102+
.await;
103103

104104
resolved_ids.into_batched_result()
105105
}
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1+
use futures::future::join_all;
12
use rolldown_common::IntoBatchedResult;
23
use rolldown_plugin::{HookRenderChunkArgs, SharedPluginDriver};
34
use rolldown_sourcemap::collapse_sourcemaps;
4-
use rolldown_utils::block_on_spawn_all;
55

66
use crate::{chunk::ChunkRenderReturn, error::BatchedErrors};
77

88
pub async fn render_chunks<'a>(
99
plugin_driver: &SharedPluginDriver,
1010
chunks: Vec<ChunkRenderReturn>,
1111
) -> Result<Vec<ChunkRenderReturn>, BatchedErrors> {
12-
let result = block_on_spawn_all(chunks.into_iter().map(|chunk| async move {
12+
join_all(chunks.into_iter().map(|chunk| async move {
1313
tracing::info!("render_chunks");
14-
match plugin_driver
14+
plugin_driver
1515
.render_chunk(HookRenderChunkArgs { code: chunk.code, chunk: &chunk.rendered_chunk })
1616
.await
17-
{
18-
Ok((code, render_chunk_sourcemap_chain)) => Ok(ChunkRenderReturn {
17+
.map(|(code, render_chunk_sourcemap_chain)| ChunkRenderReturn {
1918
code,
2019
map: if render_chunk_sourcemap_chain.is_empty() {
2120
chunk.map
@@ -28,10 +27,8 @@ pub async fn render_chunks<'a>(
2827
collapse_sourcemaps(sourcemap_chain, None)
2928
},
3029
rendered_chunk: chunk.rendered_chunk,
31-
}),
32-
Err(e) => Err(e),
33-
}
34-
}));
35-
36-
result.into_batched_result()
30+
})
31+
}))
32+
.await
33+
.into_batched_result()
3734
}

crates/rolldown_utils/Cargo.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,3 @@ repository.workspace = true
1111

1212
[lints]
1313
workspace = true
14-
15-
[dependencies]
16-
17-
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
18-
async-scoped = { workspace = true, features = ["use-tokio"] }
19-
20-
[target.'cfg(target_arch = "wasm32")'.dependencies]
21-
futures = { workspace = true, features = ["executor"] }

crates/rolldown_utils/src/lib.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,3 @@
33
mod bitset;
44

55
pub use bitset::BitSet;
6-
use std::future::Future;
7-
8-
#[cfg(not(target_arch = "wasm32"))]
9-
pub fn block_on_spawn_all<Iter, Out>(iter: Iter) -> Vec<Out>
10-
where
11-
Iter: Iterator,
12-
Out: Send + 'static,
13-
Iter::Item: Future<Output = Out> + Send,
14-
{
15-
use async_scoped::TokioScope;
16-
let (_ret, collections) =
17-
async_scoped::Scope::scope_and_block(|scope: &mut TokioScope<'_, _>| {
18-
iter.into_iter().for_each(|fut| scope.spawn(fut));
19-
});
20-
collections.into_iter().map(Result::unwrap).collect()
21-
}
22-
23-
#[cfg(target_arch = "wasm32")]
24-
pub fn block_on_spawn_all<Iter, Out>(iter: Iter) -> Vec<Out>
25-
where
26-
Iter: Iterator,
27-
Out: Send + 'static,
28-
Iter::Item: Future<Output = Out> + Send,
29-
{
30-
use futures::{executor::block_on, future};
31-
block_on(future::join_all(iter))
32-
}

0 commit comments

Comments
 (0)