Cancellation and reset()

reset() and destroying the injection context abort the calls in flight: their AbortSignal fires, they run no callback, and mutate() rejects with an AbortError. Aborting never undoes a write the server already received. Source: reset · queued reset · destroy

reset() during a call

idle

Create "Ada", then reset before the 2 s (an artificial delay) are over.

Callbacks and mutate()

  1. Nothing yet.

Server

  1. Nothing yet.
protected readonly createUser = mutation<string, User, Error>({
  mutationFn: (name, abortSignal) => this.server.createUser(name, abortSignal),
  onSuccess: (user) => this.log.add(`onSuccess("${user.name}")`),
});
<button type="button" (click)="createUser.reset()">Reset</button>

reset() while a call is queued

"Second" waits for "First" (concurrency: 'queue'). Reset before "First" settles (2 s, an artificial delay).

mutate()

  1. Nothing yet.

Server

  1. Nothing yet.
protected readonly createUser = mutation<string, User, Error>({
  concurrency: 'queue',
  mutationFn: (name, abortSignal) => this.server.createUser(name, abortSignal),
});

protected createTwo(): void {
  for (const name of ['First', 'Second']) {
    this.createUser
      .mutate(name)
      .catch((error: Error) =>
        this.log.add(`mutate("${name}") rejected: '${error.message}', wasNeverSent: ${wasNeverSent(error)}`),
      );
  }
}

Destroy

Create "Grace", destroy the injector while the call is in flight, then create "Grace" again.

Callbacks and mutate()

  1. Nothing yet.

Server

  1. Nothing yet.
private readonly childInjector = createEnvironmentInjector([], inject(EnvironmentInjector));

protected readonly createUser = mutation<string, User, Error>({
  injector: this.childInjector,
  mutationFn: (name, abortSignal) => this.server.createUser(name, abortSignal),
  onSuccess: (user) => this.log.add(`onSuccess("${user.name}")`),
});

this.childInjector.destroy();