Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix issue where interator thread was continuing to capture input from std #150

Merged
merged 1 commit into from

3 participants

@f1sherman

I was able to reproduce and resolve the issue reported here with this commit:
#149

Sorry about that!

Thanks again

/Brian

@rymai rymai merged commit 9108563 into from
@rymai
Owner

@hardipe could you try using Guard directly from the master and confirm us the problem is solved? Thanks!

@hardipe

@rymai Yep, using 0.8.4 master, and it is working perfectly now! Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 2, 2011
  1. @f1sherman

    fix issue where interator thread was continuing to capture input from…

    f1sherman authored
    … stdin while a guard is being executed
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 16 deletions.
  1. +5 −2 lib/guard.rb
  2. +20 −14 lib/guard/interactor.rb
View
7 lib/guard.rb
@@ -29,6 +29,8 @@ class << self
# @option options [Boolean] watch_all_modifications watches all file modifications if true
#
def setup(options = {})
+ @lock = Mutex.new
+
@options = options
@guards = []
@groups = [Group.new(:default)]
@@ -41,8 +43,6 @@ def setup(options = {})
debug_command_execution if @options[:debug]
- @lock = Mutex.new
-
self
end
@@ -180,9 +180,12 @@ def run
@lock.synchronize do
begin
+ @interactor.stop_if_not_current
yield
rescue Interrupt
end
+
+ @interactor.start
end
end
View
34 lib/guard/interactor.rb
@@ -11,28 +11,34 @@ module Guard
# - Everything else => Run all
#
class Interactor
-
# Start the interactor in its own thread.
#
def start
return if ENV["GUARD_ENV"] == 'test'
- @thread = Thread.new do
- while entry = $stdin.gets.chomp
- entry.gsub! /\n/, ''
- case entry
- when 'stop', 'quit', 'exit', 's', 'q', 'e'
- ::Guard.stop
- when 'reload', 'r', 'z'
- ::Guard::Dsl.reevaluate_guardfile
- ::Guard.reload
- when 'pause', 'p'
- ::Guard.pause
- else
- ::Guard.run_all
+ if !@thread || @thread.stop?
+ @thread = Thread.new do
+ while entry = $stdin.gets.chomp
+ case entry
+ when 'stop', 'quit', 'exit', 's', 'q', 'e'
+ ::Guard.stop
+ when 'reload', 'r', 'z'
+ ::Guard::Dsl.reevaluate_guardfile
+ ::Guard.reload
+ when 'pause', 'p'
+ ::Guard.pause
+ else
+ ::Guard.run_all
+ end
end
end
end
end
+
+ def stop_if_not_current
+ unless Thread.current == @thread
+ @thread.kill
+ end
+ end
end
end
Something went wrong with that request. Please try again.