Skip to content

Commit d3106cd

Browse files
authored
Simplify spawn_blocking() wrapper fn (#10002)
The idea for our wrapper to require a `Result` return type for the callback function might have been good in theory, but leads to too many small annoyances in practice. Let's get rid of it and move back closer to the original `spawn_blocking()` implementation from `tokio`.
1 parent e583ce6 commit d3106cd

25 files changed

+37
-48
lines changed

src/bin/crates-admin/default_versions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ pub async fn run(command: Command) -> anyhow::Result<()> {
4848

4949
Ok(())
5050
})
51-
.await
51+
.await?
5252
}

src/bin/crates-admin/delete_version.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
6464
}
6565
}
6666

67-
let opts = spawn_blocking::<_, _, anyhow::Error>(move || {
67+
let opts = spawn_blocking(move || {
6868
use diesel::RunQueryDsl;
6969

7070
let conn: &mut AsyncConnectionWrapper<_> = &mut conn.into();
@@ -110,8 +110,8 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
110110
warn!(%crate_name, ?error, "Failed to enqueue SyncToSparseIndex job");
111111
}
112112

113-
Ok(opts)
114-
}).await?;
113+
Ok::<_, anyhow::Error>(opts)
114+
}).await??;
115115

116116
let crate_name = &opts.crate_name;
117117

src/bin/crates-admin/dialoguer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crates_io::tasks::spawn_blocking;
33

44
pub async fn confirm(msg: impl Into<String>) -> anyhow::Result<bool> {
55
let msg = msg.into();
6-
spawn_blocking(move || sync_confirm(msg).map_err(anyhow::Error::from)).await
6+
spawn_blocking(move || sync_confirm(msg).map_err(anyhow::Error::from)).await?
77
}
88

99
fn sync_confirm(msg: impl Into<String>) -> dialoguer::Result<bool> {

src/bin/crates-admin/migrate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub async fn run(_opts: Opts) -> Result<(), Error> {
5454

5555
Ok::<_, Error>(conn)
5656
})
57-
.await?;
57+
.await??;
5858

5959
info!("Synchronizing crate categories");
6060
crates_io::boot::categories::sync_with_connection(CATEGORIES_TOML, &mut conn).await?;

src/bin/crates-admin/render_readmes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async fn get_readme(
175175
let archive = Archive::new(reader);
176176
render_pkg_readme(archive, &pkg_name)
177177
})
178-
.await
178+
.await?
179179
}
180180

181181
fn render_pkg_readme<R: Read>(mut archive: Archive<R>, pkg_name: &str) -> anyhow::Result<String> {

src/bin/crates-admin/upload_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
3030

3131
Ok::<_, anyhow::Error>((repo, files))
3232
})
33-
.await?;
33+
.await??;
3434

3535
if !dialoguer::confirm("continue with upload?").await? {
3636
return Ok(());

src/controllers/crate_owner_invitation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub async fn list(app: AppState, req: Parts) -> AppResult<ErasedJson> {
6565
"users": users,
6666
}))
6767
})
68-
.await
68+
.await?
6969
}
7070

7171
/// Handles the `GET /api/private/crate_owner_invitations` route.
@@ -86,7 +86,7 @@ pub async fn private_list(app: AppState, req: Parts) -> AppResult<Json<PrivateLi
8686
let list = prepare_list(&app, &req, auth, filter, conn)?;
8787
Ok(Json(list))
8888
})
89-
.await
89+
.await?
9090
}
9191

9292
enum ListFilter {

src/controllers/keyword.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub async fn index(state: AppState, qp: Query<IndexQuery>, req: Parts) -> AppRes
4646
"meta": { "total": total },
4747
}))
4848
})
49-
.await
49+
.await?
5050
}
5151

5252
/// Handles the `GET /keywords/:keyword_id` route.

src/controllers/krate/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub async fn show(app: AppState, Path(name): Path<String>, req: Parts) -> AppRes
164164
"categories": encodable_cats,
165165
}))
166166
})
167-
.await
167+
.await?
168168
}
169169

170170
#[derive(Debug)]

src/controllers/krate/owners.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub async fn owner_user(state: AppState, Path(crate_name): Path<String>) -> AppR
8080

8181
Ok(json!({ "users": owners }))
8282
})
83-
.await
83+
.await?
8484
}
8585

8686
/// Handles the `PUT /crates/:crate_id/owners` route.
@@ -246,7 +246,7 @@ async fn modify_owners(
246246

247247
Ok(json!({ "msg": comma_sep_msg, "ok": true }))
248248
})
249-
.await
249+
.await?
250250
}
251251

252252
pub struct OwnerInviteEmail {

0 commit comments

Comments
 (0)