class Listen::Event::Loop
Constants
- Error
- MAX_STARTUP_SECONDS
- NotStarted
Public Class Methods
new(config)
click to toggle source
# File lib/listen/event/loop.rb, line 24 def initialize(config) @config = config @wait_thread = nil @reasons = ::Queue.new initialize_fsm end
Public Instance Methods
pause()
click to toggle source
# File lib/listen/event/loop.rb, line 62 def pause # TODO: works? # fail NotImplementedError end
start()
click to toggle source
@raises Error::NotStarted
if background thread hasn’t started in MAX_STARTUP_SECONDS
# File lib/listen/event/loop.rb, line 44 def start # TODO: use a Fiber instead? return unless state == :pre_start transition! :starting @wait_thread = Listen::Thread.new("wait_thread") do _process_changes end Listen.logger.debug("Waiting for processing to start...") wait_for_state(:started, timeout: MAX_STARTUP_SECONDS) or raise Error::NotStarted, "thread didn't start in #{MAX_STARTUP_SECONDS} seconds (in state: #{state.inspect})" Listen.logger.debug('Processing started.') end
started?()
click to toggle source
# File lib/listen/event/loop.rb, line 37 def started? state == :started end
stop()
click to toggle source
# File lib/listen/event/loop.rb, line 67 def stop transition! :stopped @wait_thread&.join @wait_thread = nil end
stopped?()
click to toggle source
# File lib/listen/event/loop.rb, line 74 def stopped? state == :stopped end
wakeup_on_event()
click to toggle source
# File lib/listen/event/loop.rb, line 31 def wakeup_on_event if started? && @wait_thread&.alive? _wakeup(:event) end end
Private Instance Methods
_process_changes()
click to toggle source
# File lib/listen/event/loop.rb, line 80 def _process_changes processor = Event::Processor.new(@config, @reasons) transition! :started processor.loop_for(@config.min_delay_between_events) end
_wakeup(reason)
click to toggle source
# File lib/listen/event/loop.rb, line 88 def _wakeup(reason) @reasons << reason @wait_thread.wakeup end