Module: Roast::EventMonitor
- Extended by:
- EventMonitor
- Includes:
- Kernel
- Included in:
- EventMonitor
- Defined in:
- lib/roast/event_monitor.rb
Defined Under Namespace
Classes: EventMonitorAlreadyStartedError, EventMonitorError, EventMonitorNotRunningError
Constant Summary collapse
- BLOCK_SEPARATOR =
: String
("─" * 40).freeze
Instance Method Summary collapse
-
#accept(event) ⇒ Object
: (Event) -> void.
-
#reset! ⇒ Object
: () -> void.
-
#running? ⇒ Boolean
: () -> bool.
-
#start! ⇒ Object
: () -> Async::Task.
-
#stop! ⇒ Object
: () -> void.
Instance Method Details
#accept(event) ⇒ Object
: (Event) -> void
60 61 62 63 64 65 66 |
# File 'lib/roast/event_monitor.rb', line 60 def accept(event) if running? @queue.push(event) else handle_event(event) end end |
#reset! ⇒ Object
: () -> void
53 54 55 56 57 |
# File 'lib/roast/event_monitor.rb', line 53 def reset! OutputRouter.disable! @queue.close @task = nil end |
#running? ⇒ Boolean
: () -> bool
21 22 23 |
# File 'lib/roast/event_monitor.rb', line 21 def running? !@queue.closed? end |
#start! ⇒ Object
: () -> Async::Task
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/roast/event_monitor.rb', line 26 def start! raise EventMonitorAlreadyStartedError if running? OutputRouter.enable! @queue = Async::Queue.new @task = Async(transient: true) do OutputRouter.mark_as_output_fiber! loop do event = @queue.pop #: as Event? break if event.nil? handle_event(event) end end end |
#stop! ⇒ Object
: () -> void
43 44 45 46 47 48 49 50 |
# File 'lib/roast/event_monitor.rb', line 43 def stop! raise EventMonitorNotRunningError unless running? OutputRouter.disable! @queue.close @task&.wait @task = nil end |