The instrument
Everything below is the library, compiled for this browser: the registry in this process
with a clock, hold keeping one endpoint alive,
View following both services, and a sweeper ending leases whose
time has run out. Nothing on the page is a mock-up of a registry; the page is reading one.
What you are watching
A registration is only as good as its renewal. Hold an instance puts the whole loop
inside the library: hold registers, renews at a third of the lease,
and deregisters when the task is cancelled. Lease one by hand registers once and
leaves the renewal to this page, which is what a caller with its own timer does — and what
makes a lapse visible: stop pressing ↻ and the bar empties, the sweeper drops the lease, and
the watcher reports the endpoint leaving.
| On the board | In the library | When it ends |
|---|---|---|
hold | hold(registry, service, endpoint, ttl) in its own task | the task is cancelled, which deregisters first |
lease | register(service, endpoint, ttl), then renew(lease) | nobody renews it, and the clock passes the lease |
The revision in the header is the number the watcher last reported. It grows with each change, which is how the page knows something happened without diffing the list.
Under the page
The engine is src/examples/browser in the repository, built to
JavaScript by the documentation workflow and served from engine/.
It exports seven functions — ready, join,
lease_manually, renew,
withdraw, reset,
state — and the page calls them; the registry, the leases and the
watchers are all MoonBit.
The clock is the monotonic clock of the runtime, the sweep runs every 200 ms, and the lease is 8 s so a lapse fits on a screen. Nothing here is a special case inside the library: the same calls on a Redis, etcd or Consul registry behave the same way, only the latency of a change differs.