Save per document

Saving several documents: the saves of one document must stay in order, but needn't wait for another document's. { queue, key } gives each document its own line in a mutationQueue(); a call without a key, such as Delete all, waits for every document. Source

Click Save A twice, then Save B; then Save A, then Delete all. Saving A takes 1.5 s, the rest 0.3 s (artificial delays).

save.pendingInputs()
—
removeAll.status()
idle
server
A: draft · B: draft

A's saves stay in order, B doesn't wait, Delete all comes after A.

Server

  1. Nothing yet.
private readonly documentWrites = mutationQueue();

protected readonly save = mutation<Draft, void, Error>({
  concurrency: { queue: this.documentWrites, key: (draft) => draft.docId },
  mutationFn: (draft, abortSignal) => this.server.save(draft, abortSignal),
});

// No key: waits for the saves of every document, and the saves made after it wait for it.
protected readonly removeAll = mutation<void, void, Error>({
  concurrency: this.documentWrites,
  mutationFn: (_input, abortSignal) => this.server.removeAll(abortSignal),
});