pub fn mutate<V, T, E, C, F, Fut>(
entity: &Entity<MutationResource<V, T, E>>,
variables: V,
mutator: F,
cx: &mut Context<'_, C>,
)hook only.Expand description
Trigger a mutation on an existing mutation entity.
This is the primary way to execute mutations. It:
- Transitions the entity to Loading with the given variables
- Spawns an async task calling the mutator
- On success, completes with the result data
- On failure, retries according to the entity’s retry policy
Audit fix #8/#7: Guards against concurrent calls by checking whether the
mutation is already in Loading state inside the same entity.update that
calls begin, so the check+begin is atomic and a racing caller cannot
slip a begin in between. If already Loading, returns without starting a
new mutation.
Audit fix #3: Variables are wrapped in Arc<V> internally so that the
retry loop only performs an Arc::clone (cheap reference count increment)
per attempt, rather than cloning the full variables payload. For the
no-V::clone-per-attempt path, prefer mutate_by_ref or
mutate_arc.
Audit fix #6: The spawned task is stored on the resource via
set_current_task so a replacement call (or entity drop) aborts the prior
in-flight task. Previously the task was .detach()ed and kept running
after unmount/replacement.
Audit fix #67: The shared guard/begin/spawn logic lives in
[begin_and_spawn] and is shared with mutate_with_callbacks.
Audit fix #119: The unused + Clone bound on F has been dropped — the
mutator is only ever borrowed, never cloned.
§Example
use gpui_query::hook::mutate;
mutate(entity, Vars, |v| async move { Ok(Data) }, cx);