RTCForge API Reference v1.1.1
    Preparing search index...

    Class MemoryMembership

    In-process Membership backed by a Map with TTL-based expiry.

    The default implementation for single-node deployments and tests: nodes are held in memory, each with an expiry derived from the ttlMs passed to register. Entries whose TTL has lapsed are pruned lazily on list and, if a sweepIntervalMs is supplied, proactively by a background timer that fires watchers when a silently-dead node expires. Watchers receive the full live set on every change. For multi-node clusters use GossipMembership instead.

    Implements

    Index

    Constructors

    • Parameters

      • _clock: Clock = systemClock

        Time source used for TTL expiry.

      • OptionalsweepIntervalMs: number

        When set (> 0), a background timer prunes expired nodes every this-many milliseconds and notifies watchers, so a silently-dead node's TTL expiry fires watch/reconciler onRemove without anything having to poll list. Omit to disable (watchers then only fire on register/deregister and explicit list()).

      Returns MemoryMembership

    Methods

    • Registers (or refreshes) a node with a heartbeat lifetime.

      Parameters

      • node: NodeInfo

        The node to register.

      • ttlMs: number

        Lifetime in milliseconds; the node is considered gone if not refreshed within this window.

      Returns Promise<void>

    • Subscribes to membership changes.

      Parameters

      • callback: (nodes: NodeInfo[]) => void

        Invoked with the full set of live nodes whenever membership changes.

      Returns () => void

      A function that cancels the subscription when called.