Skip to content
Browse files

Fix pause/unpause example in README

and add listener#wait_until_it_starts method
  • Loading branch information...
1 parent 45d5ec8 commit 8d8156249e1dd74385a1387bdf6d03f7a8164ae0 Thibaud Guillaume-Gentil committed
Showing with 13 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +4 −2 README.md
  3. +1 −1 lib/listen/adapter.rb
  4. +7 −1 lib/listen/listener.rb
View
1 .gitignore
@@ -4,6 +4,7 @@ doc/*
*.rbc
.*.swp
*.bak
+bundle
.bundle
.yardoc
.rbx
View
6 README.md
@@ -100,10 +100,12 @@ Listener can also easily be paused/unpaused:
``` ruby
listener = Listen.to('dir/path/to/listen')
-listener.start # enter the run loop
+Thread.new { listener.start } # enter the run loop
+listener.wait_until_it_starts
listener.pause # stop listening changes
-listener.paused? => true
+listener.paused? # => true
listener.unpause
+listener.wait_until_it_starts
listener.stop
```
View
2 lib/listen/adapter.rb
@@ -2,7 +2,7 @@
module Listen
class Adapter
- attr_accessor :latency, :paused
+ attr_accessor :latency, :stop, :paused
# The default delay between checking for changes.
DEFAULT_LATENCY = 0.1
View
8 lib/listen/listener.rb
@@ -76,7 +76,13 @@ def unpause
# @return [Boolean] adapter paused status
#
def paused?
- !@adapter.nil? && @adapter.paused == true
+ !!@adapter && @adapter.paused == true
+ end
+
+ # Block until the adapter started or has been unpaused
+ #
+ def wait_until_it_starts
+ sleep 0.1 while @adapter.nil? || (@adapter.stop != false && @adapter.paused != false)
end
# Add ignored path to the listener.

0 comments on commit 8d81562

Please sign in to comment.
Something went wrong with that request. Please try again.