pub struct QueryRuntime { /* private fields */ }Expand description
The query runtime manages query execution, caching, and dependency tracking.
This is cheap to clone - all data is behind Arc.
§Example
let runtime = QueryRuntime::new();
// Sync query execution
let result = runtime.query(MyQuery { ... })?;
// Async query execution (waits through Suspend)
let result = runtime.query_async(MyQuery { ... }).await?;Implementations§
Source§impl QueryRuntime
impl QueryRuntime
Sourcepub fn builder() -> QueryRuntimeBuilder
pub fn builder() -> QueryRuntimeBuilder
Sourcepub fn query<Q: Query>(&self, query: Q) -> Result<Arc<Q::Output>, QueryError>
pub fn query<Q: Query>(&self, query: Q) -> Result<Arc<Q::Output>, QueryError>
Execute a query synchronously.
Returns the cached result if valid, otherwise executes the query.
§Errors
QueryError::Suspend- Query is waiting for async loadingQueryError::Cycle- Dependency cycle detected
Sourcepub fn invalidate<Q: Query>(&self, key: &Q::CacheKey)
pub fn invalidate<Q: Query>(&self, key: &Q::CacheKey)
Invalidate a query, forcing recomputation on next access.
This also invalidates any queries that depend on this one.
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clear all cached values.
Source§impl QueryRuntime
impl QueryRuntime
Sourcepub fn register_asset_locator<K, L>(&self, locator: L)where
K: AssetKey,
L: AssetLocator<K>,
pub fn register_asset_locator<K, L>(&self, locator: L)where
K: AssetKey,
L: AssetLocator<K>,
Sourcepub fn pending_assets(&self) -> Vec<PendingAsset>
pub fn pending_assets(&self) -> Vec<PendingAsset>
Get an iterator over pending asset requests.
Returns assets that have been requested but not yet resolved.
The user should fetch these externally and call resolve_asset().
§Example
for pending in runtime.pending_assets() {
if let Some(path) = pending.key::<FilePath>() {
let content = fetch_file(path);
runtime.resolve_asset(path.clone(), content);
}
}Sourcepub fn pending_assets_of<K: AssetKey>(&self) -> Vec<K>
pub fn pending_assets_of<K: AssetKey>(&self) -> Vec<K>
Get pending assets filtered by key type.
Sourcepub fn has_pending_assets(&self) -> bool
pub fn has_pending_assets(&self) -> bool
Check if there are any pending assets.
Sourcepub fn resolve_asset<K: AssetKey>(&self, key: K, value: K::Asset)
pub fn resolve_asset<K: AssetKey>(&self, key: K, value: K::Asset)
Resolve an asset with its loaded value.
This marks the asset as ready and invalidates any queries that depend on it (if the value changed), triggering recomputation on next access.
This method is idempotent - resolving with the same value (via asset_eq)
will not trigger downstream recomputation.
Uses the asset key’s default durability.
§Example
let content = std::fs::read_to_string(&path)?;
runtime.resolve_asset(FilePath(path), content);Sourcepub fn resolve_asset_with_durability<K: AssetKey>(
&self,
key: K,
value: K::Asset,
durability: DurabilityLevel,
)
pub fn resolve_asset_with_durability<K: AssetKey>( &self, key: K, value: K::Asset, durability: DurabilityLevel, )
Resolve an asset with a specific durability level.
Use this to override the asset key’s default durability.
Sourcepub fn invalidate_asset<K: AssetKey>(&self, key: &K)
pub fn invalidate_asset<K: AssetKey>(&self, key: &K)
Invalidate an asset, forcing queries to re-request it.
The asset will be marked as loading and added to pending assets. Dependent queries will suspend until the asset is resolved again.
§Example
// File was modified externally
runtime.invalidate_asset(&FilePath("config.json".into()));
// Queries depending on this asset will now suspend
// User should fetch the new value and call resolve_assetSourcepub fn remove_asset<K: AssetKey>(&self, key: &K)
pub fn remove_asset<K: AssetKey>(&self, key: &K)
Remove an asset from the cache entirely.
Unlike invalidate_asset, this removes all traces of the asset.
Dependent queries will go through the locator again on next access.