pub struct SharedHttpClient { /* private fields */ }Expand description
A deduplicating HTTP client wrapper that can be cheaply cloned.
Every clone shares the same inner HTTP client and in-flight
tracking state, but each clone has a unique subscriber identity
so that poll returns only the responses
relevant to that subscriber.
§Construction
use rustial_engine::{SharedHttpClient, HttpClient};
let inner: Box<dyn HttpClient> = /* host-provided client */;
let shared = SharedHttpClient::new(inner);
// Hand clones to different tile sources:
let raster_client: Box<dyn HttpClient> = Box::new(shared.clone());
let vector_client: Box<dyn HttpClient> = Box::new(shared.clone());Implementations§
Sourcepub fn new(client: Box<dyn HttpClient>) -> Self
pub fn new(client: Box<dyn HttpClient>) -> Self
Wrap an existing HTTP client with cross-source deduplication.
The returned handle is subscriber 0. Call clone
to create additional subscribers.
Trait Implementations§
Source§fn send(&self, request: HttpRequest)
fn send(&self, request: HttpRequest)
Send an HTTP request, deduplicating against in-flight requests.
If another subscriber has already sent a request for the same URL, this subscriber is added to the waiting list without issuing a duplicate fetch to the inner client.
Source§fn poll(&self) -> Vec<(String, Result<HttpResponse, String>)>
fn poll(&self) -> Vec<(String, Result<HttpResponse, String>)>
Poll for completed responses belonging to this subscriber.
Internally polls the shared inner client and distributes completed responses to all subscribers that requested each URL. Returns only the responses destined for this subscriber.