SolidJS — 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 createSharedValue builds its own observe(). Hoist it to module scope and wrap with createObservable — all subscribers share one field watch; onCleanup still disposes per owner.

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

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

// in a component: const p = createObservable(pressure); // shared watch

Write back to shared memory

reactive() wraps a connector as a signal-tracked view whose set() writes through to the buffer — the worker reads it on its side. observeRemote() tracks writes coming back.

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

const seedProgress = reactive(
  incidentsMemory.connector('signals.seedProgress'),
);
const stopRemote = seedProgress.observeRemote();  // worker → main
seedProgress.set(0);                              // main → worker

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

Pool lifecycle & stats

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

frontend
import { onCleanup } from 'solid-js';

onCleanup(() => incidents.terminate());   // owner teardown → pool down

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