Skip to content

Commit

Permalink
simplify away some async blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Dec 27, 2023
1 parent ff83122 commit 7da4a76
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
4 changes: 1 addition & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ pub fn channel(endpoint: Endpoint, key: Option<Key>, logger: Logger) -> (ApiStub

pub fn spawn(endpoint: Endpoint, key: Option<Key>, logger: Logger) -> ApiStub {
let (stub, actor) = channel(endpoint, key, logger);
tokio::spawn(async move {
actor.run().await;
});
tokio::spawn(actor.run());
stub
}

Expand Down
16 changes: 4 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ async fn run(opt: Opt, logger: &Logger) {
// Spawn API actor.
let api = {
let (api, api_actor) = api::channel(endpoint.clone(), opt.key, logger.clone());
join_handles.push(tokio::spawn(async move {
api_actor.run().await;
}));
join_handles.push(tokio::spawn(api_actor.run()));
api
};

Expand All @@ -148,9 +146,7 @@ async fn run(opt: Opt, logger: &Logger) {
opt.max_backoff.unwrap_or_default(),
logger.clone(),
);
join_handles.push(tokio::spawn(async move {
queue_actor.run().await;
}));
join_handles.push(tokio::spawn(queue_actor.run()));
queue
};

Expand All @@ -163,9 +159,7 @@ async fn run(opt: Opt, logger: &Logger) {
let assets = assets.clone();
let tx = tx.clone();
let logger = logger.clone();
join_handles.push(tokio::spawn(async move {
worker(i, assets, tx, logger).await;
}));
join_handles.push(tokio::spawn(worker(i, assets, tx, logger)));
}
rx
};
Expand Down Expand Up @@ -317,9 +311,7 @@ async fn worker(i: usize, assets: Arc<Assets>, tx: mpsc::Sender<Pull>, logger: L
},
logger.clone(),
);
let join_handle = tokio::spawn(async move {
sf_actor.run().await;
});
let join_handle = tokio::spawn(sf_actor.run());
(sf, join_handle)
};

Expand Down

0 comments on commit 7da4a76

Please sign in to comment.