Merge pull request #150 from f1sherman/use_mutex_instead_of_lock
fix issue where interator thread was continuing to capture input from std
This commit is contained in:
commit
910856362e
@ -29,6 +29,8 @@ module Guard
|
|||||||
# @option options [Boolean] watch_all_modifications watches all file modifications if true
|
# @option options [Boolean] watch_all_modifications watches all file modifications if true
|
||||||
#
|
#
|
||||||
def setup(options = {})
|
def setup(options = {})
|
||||||
|
@lock = Mutex.new
|
||||||
|
|
||||||
@options = options
|
@options = options
|
||||||
@guards = []
|
@guards = []
|
||||||
@groups = [Group.new(:default)]
|
@groups = [Group.new(:default)]
|
||||||
@ -41,8 +43,6 @@ module Guard
|
|||||||
|
|
||||||
debug_command_execution if @options[:debug]
|
debug_command_execution if @options[:debug]
|
||||||
|
|
||||||
@lock = Mutex.new
|
|
||||||
|
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -180,9 +180,12 @@ module Guard
|
|||||||
|
|
||||||
@lock.synchronize do
|
@lock.synchronize do
|
||||||
begin
|
begin
|
||||||
|
@interactor.stop_if_not_current
|
||||||
yield
|
yield
|
||||||
rescue Interrupt
|
rescue Interrupt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@interactor.start
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,28 +11,34 @@ module Guard
|
|||||||
# - Everything else => Run all
|
# - Everything else => Run all
|
||||||
#
|
#
|
||||||
class Interactor
|
class Interactor
|
||||||
|
|
||||||
# Start the interactor in its own thread.
|
# Start the interactor in its own thread.
|
||||||
#
|
#
|
||||||
def start
|
def start
|
||||||
return if ENV["GUARD_ENV"] == 'test'
|
return if ENV["GUARD_ENV"] == 'test'
|
||||||
|
|
||||||
@thread = Thread.new do
|
if !@thread || @thread.stop?
|
||||||
while entry = $stdin.gets.chomp
|
@thread = Thread.new do
|
||||||
entry.gsub! /\n/, ''
|
while entry = $stdin.gets.chomp
|
||||||
case entry
|
case entry
|
||||||
when 'stop', 'quit', 'exit', 's', 'q', 'e'
|
when 'stop', 'quit', 'exit', 's', 'q', 'e'
|
||||||
::Guard.stop
|
::Guard.stop
|
||||||
when 'reload', 'r', 'z'
|
when 'reload', 'r', 'z'
|
||||||
::Guard::Dsl.reevaluate_guardfile
|
::Guard::Dsl.reevaluate_guardfile
|
||||||
::Guard.reload
|
::Guard.reload
|
||||||
when 'pause', 'p'
|
when 'pause', 'p'
|
||||||
::Guard.pause
|
::Guard.pause
|
||||||
else
|
else
|
||||||
::Guard.run_all
|
::Guard.run_all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stop_if_not_current
|
||||||
|
unless Thread.current == @thread
|
||||||
|
@thread.kill
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user