pub struct QueryManager { /* private fields */ }Expand description
Manages multiple in-flight queries in parallel using promises.
Tracks queries by unique ID (typically a pane ID), enabling Grafana-style parallel refresh where all panels query simultaneously.
Includes timeout detection to prevent queries from hanging indefinitely.
§Example
let mut manager = QueryManager::new();
// Fire multiple queries in parallel
manager.execute(pane_id_1, &client, request1, &ctx);
manager.execute(pane_id_2, &client, request2, &ctx);
// In update loop, poll for all completed results
for (id, result) in manager.poll_all() {
// Handle result for pane with this id
}Implementations§
Source§impl QueryManager
impl QueryManager
Sourcepub fn with_timeout(timeout_secs: u64) -> Self
pub fn with_timeout(timeout_secs: u64) -> Self
Create a new query manager with a custom timeout.
Sourcepub fn is_querying(&self) -> bool
pub fn is_querying(&self) -> bool
Check if any queries are currently in flight.
Sourcepub fn is_querying_id(&self, id: usize) -> bool
pub fn is_querying_id(&self, id: usize) -> bool
Check if a specific query is in flight.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Get the number of queries currently in flight.
Sourcepub fn execute<C: MetricsClient + ?Sized>(
&mut self,
id: usize,
client: &C,
request: QueryRequest,
ctx: &Context,
)
pub fn execute<C: MetricsClient + ?Sized>( &mut self, id: usize, client: &C, request: QueryRequest, ctx: &Context, )
Execute a query for the given ID using the given client.
If a query for this ID is already in flight, it is cancelled and replaced.
Call poll_all() each frame to check for results.
Sourcepub fn poll_all(&mut self) -> Vec<(usize, QueryResult)>
pub fn poll_all(&mut self) -> Vec<(usize, QueryResult)>
Poll for all completed query results.
Returns a vector of (id, result) pairs for queries that completed or timed out.
Completed queries are removed from the pending set.
Sourcepub fn cancel(&mut self, id: usize)
pub fn cancel(&mut self, id: usize)
Cancel a specific query by ID.
Note: This doesn’t actually cancel the HTTP request, but it will ignore the result when it arrives.
Sourcepub fn cancel_all(&mut self)
pub fn cancel_all(&mut self)
Cancel all pending queries.