Class: Listen::Event::Loop
- Inherits:
-
Object
- Object
- Listen::Event::Loop
show all
- Includes:
- FSM
- Defined in:
- lib/listen/event/loop.rb
Constant Summary
collapse
- Error =
::Listen::Error
- NotStarted =
for backward compatibility
::Listen::Error::NotStarted
- MAX_STARTUP_SECONDS =
5.0
Instance Attribute Summary
Attributes included from FSM
#state
Instance Method Summary
collapse
Methods included from FSM
included, #initialize_fsm, #wait_for_state
Constructor Details
#initialize(config) ⇒ Loop
Returns a new instance of Loop.
24
25
26
27
28
29
|
# File 'lib/listen/event/loop.rb', line 24
def initialize(config)
@config = config
@wait_thread = nil
@reasons = ::Queue.new
initialize_fsm
end
|
Instance Method Details
#pause ⇒ Object
62
63
64
65
|
# File 'lib/listen/event/loop.rb', line 62
def pause
end
|
#start ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/listen/event/loop.rb', line 44
def start
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? ⇒ Boolean
37
38
39
|
# File 'lib/listen/event/loop.rb', line 37
def started?
state == :started
end
|
#stop ⇒ Object
67
68
69
70
71
72
|
# File 'lib/listen/event/loop.rb', line 67
def stop
transition! :stopped
@wait_thread&.join
@wait_thread = nil
end
|
#stopped? ⇒ Boolean
74
75
76
|
# File 'lib/listen/event/loop.rb', line 74
def stopped?
state == :stopped
end
|
#wakeup_on_event ⇒ Object
31
32
33
34
35
|
# File 'lib/listen/event/loop.rb', line 31
def wakeup_on_event
if started? && @wait_thread&.alive?
_wakeup(:event)
end
end
|