Class WatcherManager

java.lang.Object
net.apartium.cocoabeans.state.WatcherManager
All Implemented Interfaces:
WatcherOperator

@AvailableSince("0.0.39") public class WatcherManager extends Object implements WatcherOperator
A reference implementation of WatcherOperator, referencing watchers via an identity hash set. This implementation is thread safe. NOTE: To make an instance do anything, its heartbeat() method has to be triggered externally.
See Also:
  • Constructor Details

    • WatcherManager

      public WatcherManager()
  • Method Details

    • heartbeat

      public void heartbeat()
      Triggers heartbeat on all the attached watchers
      See Also:
    • watch

      public <T> AttachedWatcher<T> watch(Observable<T> depends, Consumer<T> consumer)
      Creates a watcher instance attached to the current instance
      Type Parameters:
      T - state element type
      Parameters:
      depends - observable to depend on
      consumer - action to run on change of the observable
      Returns:
      a new attached watcher instance
      See Also:
    • detach

      public void detach(AttachedWatcher<?> watcher)
      Detach a watcher attached with the current instance
      Specified by:
      detach in interface WatcherOperator
      Parameters:
      watcher - watcher instance