Skip to content

Architecture ​

text
adapter.observe ─► intake (copy, validate, sample clock) ─► FIFO queue
                                                           │
            ┌──────────────────────────────────────────────┘
            ▼
reduceObservation ─► commit snapshot ─► state listeners ─► transition listeners
                                         ─► reported errors ─► commit diagnostic

Ownership ​

text
CREATED ─► STARTING ─► RUNNING ─► DISPOSED
   │           └──► FAILED ──────► DISPOSED
   └─ unavailable ─► RUNNING, observing nothing
CREATED, STARTING ───────────────► DISPOSED

Pulse holds its ownership as a discriminated union. Only STARTING and RUNNING carry the observation token; an observer callback whose token is not the current one is ignored, so a failed or disposed observation can never publish. start() calls available() first; when it is false the instance runs with no observation. During setup, observations are only queued: nothing is delivered before the adapter's cleanup is owned. A dispose during setup runs that cleanup once, as soon as setup returns.

Intake and the reducer ​

#accept reads the snapshot once into its interned state (readObservation) and samples the clock once (sampleClock), then queues the record. reduceObservation is pure: the previous timeline and one observation in, the next timeline, an optional commit, an optional frozen event and whether the clock rolled back out. The clock is checked before duplicates, because a duplicate can reveal a discontinuity.

Delivery ​

The queue drains while running and not already draining, so an observation made from any callback waits behind the current commit. Both listener groups are copied before the first callback; a registration removed before its turn is skipped; disposal clears the registries, which silences the rest of the commit, and empties the queue.

Invariants and their tests ​

InvariantGuarded in
Construction and subscription observe nothingPulse.test.ts C-001, C-005
Setup cannot publish before its cleanup is ownedPulse.test.ts C-009, C-010, C-013
Equal state keeps identity and sequencetransitions.test.ts C-029, reducer pairs
Only adjacent known phase changes are transitionsreduceObservation.test.ts, oracle.test.ts
An unknown phase breaks edges and timingC-032, C-033, C-034, the oracle
Reentrant input waits behind the current commitdelivery.test.ts C-058, C-063, C-064
Listener membership is fixed before the first callbackC-059, C-060, C-061
Timing is sampled at intake; anomalies void the pairC-050 to C-057
Disposal stops every later callbackC-068, C-070, the disposal property
No entry reaches another platformverify-lint-rules.mjs, verify-packages.mjs

Released under the MIT License.