method IServiceDiscovery.watch
IServiceDiscovery.watch(
serviceName: string,
listener: (instances: readonly ServiceInstance[]) => void
): Promise<Unsubscribe>

Subscribes to instance-list changes for a service.

Push-based where the backend supports it (Consul blocking queries, Kubernetes watch streams) and interval-polled where it does not (DNS, static). The listener receives the full current list, never a delta.

Parameters

serviceName: string

Logical service name

listener: (instances: readonly ServiceInstance[]) => void

Called with the full instance list on every change

Return Type

Promise<Unsubscribe>

Unsubscribe function that also stops the underlying watch

Usage

import { type IServiceDiscovery } from "common/src/index.ts";