Skip to content

Commit

Permalink
feat: Add option to set a request timeout (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
threema-donat committed May 5, 2024
1 parent e033ae4 commit 8cd21fc
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 54 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -39,6 +39,7 @@ hyper-rustls = { version = "0.26.0", default-features = false, features = ["http
rustls-pemfile = "2.1.1"
rustls = "0.22.4"
parking_lot = "0.12"
tokio = { version = "1", features = ["time"] }

[dev-dependencies]
argparse = "0.2"
Expand Down
6 changes: 5 additions & 1 deletion examples/certificate_client.rs
Expand Up @@ -43,7 +43,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
};

let mut certificate = std::fs::File::open(certificate_file)?;
Ok(Client::certificate(&mut certificate, &password, endpoint)?)

// Create config with the given endpoint and default timeouts
let client_config = a2::ClientConfig::new(endpoint);

Ok(Client::certificate(&mut certificate, &password, client_config)?)
}
#[cfg(all(not(feature = "openssl"), feature = "ring"))]
{
Expand Down
9 changes: 7 additions & 2 deletions examples/token_client.rs
@@ -1,7 +1,9 @@
use argparse::{ArgumentParser, Store, StoreOption, StoreTrue};
use std::fs::File;

use a2::{Client, DefaultNotificationBuilder, Endpoint, NotificationBuilder, NotificationOptions};
use a2::{
client::ClientConfig, Client, DefaultNotificationBuilder, Endpoint, NotificationBuilder, NotificationOptions,
};

// An example client connectiong to APNs with a JWT token
#[tokio::main]
Expand Down Expand Up @@ -46,8 +48,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
Endpoint::Production
};

// Create config with the given endpoint and default timeouts
let client_config = ClientConfig::new(endpoint);

// Connecting to APNs
let client = Client::token(&mut private_key, key_id, team_id, endpoint).unwrap();
let client = Client::token(&mut private_key, key_id, team_id, client_config).unwrap();

let options = NotificationOptions {
apns_topic: topic.as_deref(),
Expand Down

0 comments on commit 8cd21fc

Please sign in to comment.