Macaw.Data.Source.Detector behaviour (macaw_data v0.21.1)
View SourceA change detector (spec/01 §4.5, dco-tek/macaw/macaw#108): for a source with no change
events of its own, a value that polls something cheap and answers change notices
(Macaw.Data.Source.Change) for what moved, which a source manager applies as refreshes
of exactly that (Macaw.Data.Source.Manager.notify/2).
A module implementing the behavior answers init/3, detect/2 and sees/1.
new/4, detect/2 and sees/1 here dispatch to it through a %Detector{} holding the
module and its state. It is not a process; macaw_live runs detectors, each poll in a
turn.
Summary
Callbacks
The notices for what moved over the slot ranges watched, and the state after.
The detector's state for source, with the host's context and its options.
What the detector observes, as a description's sees (spec/01 §2.1).
Functions
The notices for what moved over the slot ranges watched: {:ok, notices, detector}, or
{:error, reason, detector} with nothing lost, the next poll asking again.
A detector of module for source: {:ok, detector}, the module's init/3 error, or
{:error, :not_a_detector} for a module implementing no detector.
What the detector observes.
Types
Callbacks
@callback detect(state :: term(), ranges :: [Macaw.Data.Source.Ranges.range()]) :: {:ok, [Macaw.Data.Source.Change.t()], term()} | {:error, term(), term()}
The notices for what moved over the slot ranges watched, and the state after.
@callback init(source :: term(), context :: term(), opts :: keyword()) :: {:ok, term()} | {:error, term()}
The detector's state for source, with the host's context and its options.
@callback sees(state :: term()) :: Macaw.Data.Source.Description.sees()
What the detector observes, as a description's sees (spec/01 §2.1).
Functions
@spec detect(t(), [Macaw.Data.Source.Ranges.range()]) :: {:ok, [Macaw.Data.Source.Change.t()], t()} | {:error, term(), t()}
The notices for what moved over the slot ranges watched: {:ok, notices, detector}, or
{:error, reason, detector} with nothing lost, the next poll asking again.
A detector of module for source: {:ok, detector}, the module's init/3 error, or
{:error, :not_a_detector} for a module implementing no detector.
@spec sees(t()) :: Macaw.Data.Source.Description.sees()
What the detector observes.