Optimization: Box fut Remote::get_redirected_final_url in GhCrateMeta::find (#600)

* Box fut `Remote::get_redirected_final_url` in `GhCrateMeta::find`
   Since the other await point in `GhCrateMeta::find` only needs
   `Arc<Self>` and `handles` to be saved, which is much smaller than the
   future returned by `Remote::get_redirected_final_url`
* Refactor: Simplify `wait_on_cancellation_signal`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-12-12 19:42:11 +11:00 committed by GitHub
parent 647e340d38
commit 73a794dc13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 12 deletions

View file

@ -86,11 +86,7 @@ impl super::Fetcher for GhCrateMeta {
fn find(self: Arc<Self>) -> AutoAbortJoinHandle<Result<bool, BinstallError>> {
AutoAbortJoinHandle::spawn(async move {
let repo = if let Some(repo) = self.data.repo.as_deref() {
Some(
self.client
.get_redirected_final_url(Url::parse(repo)?)
.await?,
)
Some(Box::pin(self.client.get_redirected_final_url(Url::parse(repo)?)).await?)
} else {
None
};

View file

@ -41,16 +41,12 @@ fn ignore_signals() -> io::Result<()> {
/// that also returns `Ok(())`.
async fn wait_on_cancellation_signal() -> Result<(), io::Error> {
#[cfg(unix)]
async fn inner() -> Result<(), io::Error> {
unix::wait_on_cancellation_signal_unix().await
}
unix::wait_on_cancellation_signal_unix().await?;
#[cfg(not(unix))]
async fn inner() -> Result<(), io::Error> {
signal::ctrl_c().await
}
signal::ctrl_c().await?;
inner().await
Ok(())
}
#[cfg(unix)]