Class: Listen::Event::Loop
- Inherits:
-
Object
- Object
- Listen::Event::Loop
- Defined in:
- lib/listen/event/loop.rb
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
-
#initialize(config) ⇒ Loop
constructor
A new instance of Loop.
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #processing? ⇒ Boolean
- #resume ⇒ Object
- #setup ⇒ Object
- #stopped? ⇒ Boolean
- #teardown ⇒ Object
- #wakeup_on_event ⇒ Object
Constructor Details
#initialize(config) ⇒ Loop
12 13 14 15 16 17 |
# File 'lib/listen/event/loop.rb', line 12 def initialize(config) @config = config @wait_thread = nil @state = :paused @reasons = Thread::Queue.new end |
Instance Method Details
#pause ⇒ Object
53 54 55 56 |
# File 'lib/listen/event/loop.rb', line 53 def pause # TODO: works? # fail NotImplementedError end |
#paused? ⇒ Boolean
26 27 28 |
# File 'lib/listen/event/loop.rb', line 26 def paused? wait_thread && state == :paused end |
#processing? ⇒ Boolean
30 31 32 33 34 |
# File 'lib/listen/event/loop.rb', line 30 def processing? return false if stopped? return false if paused? state == :processing end |
#resume ⇒ Object
47 48 49 50 51 |
# File 'lib/listen/event/loop.rb', line 47 def resume fail Error::NotStarted if stopped? return unless wait_thread _wakeup(:resume) end |
#setup ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/listen/event/loop.rb', line 36 def setup # TODO: use a Fiber instead? q = Thread::Queue.new @wait_thread = Internals::ThreadPool.add do _wait_for_changes(q, config) end Listen::Logger.debug('Waiting for processing to start...') Timeout.timeout(5) { q.pop } end |
#stopped? ⇒ Boolean
67 68 69 |
# File 'lib/listen/event/loop.rb', line 67 def stopped? !wait_thread end |
#teardown ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/listen/event/loop.rb', line 58 def teardown return unless wait_thread if wait_thread.alive? _wakeup(:teardown) wait_thread.join end @wait_thread = nil end |
#wakeup_on_event ⇒ Object
19 20 21 22 23 24 |
# File 'lib/listen/event/loop.rb', line 19 def wakeup_on_event return if stopped? return unless processing? return unless wait_thread.alive? _wakeup(:event) end |