Skip to content

Commit

Permalink
Merge f2c30b4 into ba5059c
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanhefner committed Jul 21, 2020
2 parents ba5059c + f2c30b4 commit 26c3458
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/listen.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'logger'
require 'weakref'
require 'listen/logger'
require 'listen/listener'

Expand All @@ -18,6 +19,8 @@
Listen::Logger.info "Listen version: #{Listen::VERSION}"

module Listen
@listeners = Queue.new

class << self
# Listens to file system modifications on a either single directory or
# multiple directories.
Expand All @@ -32,21 +35,23 @@ class << self
# @return [Listen::Listener] the listener
#
def to(*args, &block)
@listeners ||= []
Listener.new(*args, &block).tap do |listener|
@listeners << listener
@listeners.enq(WeakRef.new(listener))
end
end

# This is used by the `listen` binary to handle Ctrl-C
#
def stop
Internals::ThreadPool.stop
@listeners ||= []

# TODO: should use a mutex for this
@listeners.each(&:stop)
@listeners = nil
while (listener = @listeners.deq(true))
begin
listener.stop
rescue WeakRef::RefError
end
end
rescue ThreadError
end
end
end

0 comments on commit 26c3458

Please sign in to comment.