Module: Plumbing::Observable
- Included in:
- Operation
- Defined in:
- lib/plumbing/observable.rb
Overview
Mix into any object — actor or not — to give it an observable event stream. The host gains a public subscriber interface (observe / remove / remove_all) and a private emit interface (push / notify), both backed by a lazily-created internal Plumbing::Pipeline::Source.
The pipeline is itself the actor, so these methods need not be async: they forward to the pipeline's async messages fire-and-forget, returning the awaitable (await it if you need the result — e.g. the observer proc that #remove expects).
Instance Method Summary collapse
-
#observe(&observer) ⇒ Object
Register an observer block.
-
#remove(observer) ⇒ Object
Deregister a previously-registered observer proc.
-
#remove_all ⇒ Object
Deregister every observer.
Instance Method Details
#observe(&observer) ⇒ Object
Register an observer block. Returns the awaitable that yields the observer proc (hand that proc to #remove later).
18 |
# File 'lib/plumbing/observable.rb', line 18 def observe(&observer) = _pipeline.observe(&observer) |
#remove(observer) ⇒ Object
Deregister a previously-registered observer proc.
21 |
# File 'lib/plumbing/observable.rb', line 21 def remove(observer) = @pipeline&.remove(observer: observer) |
#remove_all ⇒ Object
Deregister every observer.
24 |
# File 'lib/plumbing/observable.rb', line 24 def remove_all = @pipeline&.remove_all |