Svelte — advanced usage

Escape hatches past the binding layer: connectWorker tuning, per-call abort/timeout, shared observables, and pool lifecycle — same APIs under every framework's idiom.

One observable, many components

Each sharedValue builds its own observe(). Hoist it to module scope and wrap with observableValue — subscribers share one field watch; each still tears down with its owning effect.

metrics.svelte.tsfrontend
import { observe, shallowEqual } from '@atolljs/core';
import { observableValue } from '@atolljs/svelte';
import { incidentsMemory } from '@atolljs/incidents';

const pressureSource = observe(
  incidentsMemory,
  'state.metrics',
  (m) => ({ open: m.open, critical: m.critical }),
  { equals: shallowEqual },
);

export const pressure = () => observableValue(pressureSource);

Abort & timeout per call

with() attaches RunOptions to the same client surface. A queued call drops outright; an in-flight call is orphaned — the worker finishes it and the reply is discarded.

frontend
import { TaskAbortedError, TaskTimeoutError } from '@atolljs/core';

const ac = new AbortController();
const request = incidents
  .with({ signal: ac.signal, timeout: 2_000 })
  .queryIncidents(query);

ac.abort();   // rejects with TaskAbortedError

Imperative watch — outside components

watch() on a field connector fires on every write, local or remote — for logging or bridging to non-rune code. Dispose the returned function yourself.

frontend
import { watch } from '@atolljs/core';
import { incidentsMemory } from '@atolljs/incidents';

const stop = watch(
  incidentsMemory.connector('state.metrics'),
  (m) => console.log('open incidents:', m?.open),
);

stop();   // when the feature unloads

Pool lifecycle & stats

terminate() kills the pool — the next method call re-spawns it lazily. pool.stats() exposes queue/dispatch aggregates.

frontend
// $effect cleanup / onDestroy — wherever the feature tears down:
incidents.terminate();

incidents.pool?.stats();   // { workers, idle, inFlight, queued, … }