class Listen::Event::Loop
def _process_changes
def _process_changes processor = Event::Processor.new(@config, @reasons) transition! :started processor.loop_for(@config.min_delay_between_events) end
def _wakeup(reason)
def _wakeup(reason) @reasons << reason @wait_thread.wakeup end
def initialize(config)
def initialize(config) @config = config @wait_thread = nil @reasons = ::Queue.new initialize_fsm end
def pause
def pause # TODO: works? # fail NotImplementedError end
def start
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
def started?
def started? state == :started end
def stop
def stop transition! :stopped @wait_thread&.join @wait_thread = nil end
def stopped?
def stopped? state == :stopped end
def wakeup_on_event
def wakeup_on_event if started? && @wait_thread&.alive? _wakeup(:event) end end