Skip to main content

FetchPool

Struct FetchPool 

Source
pub struct FetchPool { /* private fields */ }
Expand description

A concurrency-limited, priority-ordered download scheduler.

Wraps an HttpClient and adds a bounded queue that dispatches the most important requests first.

§Example

use rustial_engine::{FetchPool, HttpClient};

let pool = FetchPool::new(my_http_client, 6);

// Batch enqueue -- no requests are sent yet.
pool.enqueue("https://tile.example.com/10/512/340.png".into(), 0.0);
pool.enqueue("https://tile.example.com/10/513/340.png".into(), 1.0);

// Dispatch the highest-priority requests up to the limit.
pool.flush();

// Later, in the frame loop:
let completed = pool.poll();  // also flushes freed slots
for (url, result) in completed {
    // handle response
}

Implementations§

Source§

impl FetchPool

Source

pub fn new(client: Box<dyn HttpClient>, max_concurrent: usize) -> Self

Create a new pool wrapping client with at most max_concurrent simultaneous downloads.

A max_concurrent of 0 is silently clamped to 1.

Source

pub fn enqueue(&self, request: HttpRequest, priority: f64)

Add a URL to the priority queue.

Lower priority = dispatched sooner. Duplicate URLs (already queued or in-flight) are silently ignored.

The request is not sent until flush is called (or implicitly via poll). This allows the caller to batch-enqueue a frame’s worth of tiles before dispatching, so the priority heap can sort them correctly.

Source

pub fn flush(&self)

Dispatch queued requests up to the concurrency limit.

The highest-priority (lowest score) requests are sent first. Call this once per frame after all enqueue calls for that frame.

Source

pub fn cancel(&self, url: &str) -> bool

Remove a URL from the pending queue if it has not been sent yet.

Returns true if the URL was found and removed. Already in-flight requests are not affected.

Source

pub fn force_cancel(&self, url: &str)

Remove a URL from the dedup set regardless of whether it is queued or in-flight.

If the URL is still in the queue it is also removed from the heap. If it is already in-flight, the concurrency slot is reclaimed immediately so that new requests can be dispatched without waiting for the ghost HTTP response to arrive. The URL is recorded in an internal set so that poll does not double-decrement in_flight when the ghost response eventually completes.

This allows the same URL to be re-enqueued immediately, which is essential when the tile manager cancels a pending tile and then re-requests it on a subsequent frame.

Source

pub fn clear_queue(&self)

Discard all queued (not yet sent) requests.

In-flight requests are unaffected – they will still appear in future poll results.

Source

pub fn queued_count(&self) -> usize

Number of requests waiting in the queue (not yet sent).

Source

pub fn max_concurrent(&self) -> usize

Maximum number of concurrent in-flight requests.

Source

pub fn in_flight_count(&self) -> usize

Number of requests currently in-flight (sent, awaiting response).

Source

pub fn known_count(&self) -> usize

Number of URLs currently tracked by the dedup set.

Source

pub fn cancelled_in_flight_count(&self) -> usize

Number of URLs recorded as force-cancelled while in-flight.

Source

pub fn is_known(&self, url: &str) -> bool

Returns true if url is known to the pool (queued or in-flight).

Source

pub fn poll(&self) -> Vec<(String, Result<HttpResponse, String>)>

Poll the underlying HttpClient for completed responses and release their concurrency slots.

Any freed slots are immediately filled from the priority queue (implicit flush).

Returns (url, Result<HttpResponse, String>) for each completed request.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.