spawn_query

Function spawn_query 

Source
pub fn spawn_query<T, V>(
    cx: &mut Context<'_, V>,
    client: &QueryClient,
    query: &Query<T>,
    on_complete: impl FnOnce(&mut V, QueryState<T>, &mut Context<'_, V>) + 'static,
)
where T: Clone + Send + Sync + Debug + 'static, V: 'static,
Expand description

Execute a query using GPUI’s executor.

This is the main entry point for running queries. It:

  • Deduplicates in-flight requests
  • Handles retries with exponential backoff
  • Caches results automatically
  • Calls your callback with the result

§Example

spawn_query(cx, &self.query_client, &users_query, |this, state, cx| {
    match state {
        QueryState::Success(users) => {
            this.users = users;
        }
        QueryState::Error { error, stale_data } => {
            this.error = Some(error.to_string());
            // Can still show stale_data if available
        }
        _ => {}
    }
    cx.notify();
});