observers property

Set<StoreObserver> get observers

Provides the set of all currently active store observers.

An observer is added to this set when it is returned from registerObserver, and removed when StoreObserver.cancel is called. When the owning Ditto instance has been closed, this returns an empty set — a closed Ditto has no active observers.

Mirrors attachmentFetchers; useful for tracking and managing ongoing observations.

Observers registered through registerObserverV2 / registerObserverWithSignalNext are not included; those return the experimental StoreObserverV2 type.

Implementation

// The `_ditto.isClosed` mask delivers the "empty after close" contract
// without draining `_observers` in `Ditto.close()`. Draining would mean
// iterating the set and calling `cancel()` on each observer; `Ditto.close()`
// is SIGABRT-sensitive (SDKS-3134, SDKS-3630, SDKS-3879), so the mask keeps
// the close path untouched. Post-close, each StoreObserver's `isCancelled`
// returns `true` via the SDKS-3916 fix, but the references remain in
// `_observers` until the owning `Store` is GC'd — this mask hides that
// internal state from callers. The asymmetry with `attachmentFetchers`
// (no close mask because `AttachmentFetcher.stop()` is wired into close
// differently) is intentional, not a copy-paste oversight.
Set<StoreObserver> get observers => _ditto.isClosed
    ? const <StoreObserver>{}
    : UnmodifiableSetView(_observers);