Skip to Content
Effetch Query
Mutations

Run modes

What happens when a mutation runs while it's already running.

When a component starts a run while its previous run is in progress, such as on a second click of a button, the mutation's concurrent decides what happens. It applies to the runs of one use, such as one component's useMutation. Separate uses, and Mutation.run calls, never affect each other:

The examples import api.ts and todos.ts from Getting started.

  • true (the default): runs overlap, and each completes.
  • false: a new run interrupts the one in progress, whose optimistic writes are rolled back first.
  • "queue": runs go one at a time, in order. A queued run counts as in progress, but its optimistic runs when it starts, so a run that fails undoes only its own writes.
  • "drop": a run started while the one result shows is in progress is ignored. It never starts or calls anything, and its run resolves at once with an interrupted Exit. After reset, a new run starts.

"drop" suits a submit button, where a second click shouldn't send the form twice:

import * as  from "effect/Schema";

import {  } from "@monarcode/effetch";

import {  } from "./api.js";
import { ,  } from "./todos.js";

export const  = .(
  .("POST /todos", {
    : .({ : . }),
    : ,
  }),
  // A click while the first run is saving does nothing.
  { : "drop", : [] },
);

To pick a mode for every mutation, set it on the client: mutations: { defaults: { concurrent: false } }.