-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: limit the max amount of concurrent network requests #116
Changes from all commits
251cf6b
45c214e
30dcf4f
7cabed4
d608dc8
d65af7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ use pipe_trait::Pipe; | |
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{package_version::PackageVersion, NetworkError, RegistryError}; | ||
use tokio::sync::Semaphore; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct Package { | ||
|
@@ -30,9 +31,11 @@ impl Package { | |
name: &str, | ||
http_client: &reqwest::Client, | ||
registry: &str, | ||
semaphore: &Semaphore, | ||
) -> Result<Self, RegistryError> { | ||
let url = || format!("{registry}{name}"); // TODO: use reqwest URL directly | ||
let network_error = |error| NetworkError { error, url: url() }; | ||
let _permit = semaphore.acquire().await; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason you gave this value a name? If you want to postpone dropping it, I recommend explicitly calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. won't it be dropped immediately if I don't assign it to a value? As far as I understand, the permit is dropped, when it goes out of scope. |
||
http_client | ||
.get(url()) | ||
.header("content-type", "application/json") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be configurable somehow