Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Listen and Pry debugging testcase
require 'listen'
require 'rb-readline' # <-- adding this fixes issues
require 'pry'
class MyGuard
attr_reader :thread
def initialize(dir)
callback = ->(*args){puts; puts "Got change: #{args.inspect}"}
@listener = Listen.to(dir).change(&callback)
end
def start
if !@thread || !@thread.alive?
@thread = Thread.new do
@listener.start
end
end
end
end
class MyInteractor
attr_reader :thread
def start
if !@thread || !@thread.alive?
@thread = Thread.new do
i = 0
while true
print "[#{i}] prompt> "
resp = gets.chomp
puts "DEBUG: received: #{resp}"
i += 1
end
end
end
end
end
class MyPry
attr_reader :thread
def start
if !@thread || !@thread.alive?
@thread = Thread.new do
Pry.start
exit
end
end
end
end
dir = Dir.pwd
puts "Listening to changes in '#{dir}'"
g = MyGuard.new dir
g.start
# Using MyInteractor works
#
# i = MyInteractor.new
# i.start
# i.thread.join
# Using MyPry blocks Listener
p = MyPry.new
p.start
p.thread.join
# This must be last thread, else the prompt won't be visible
g.thread.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.