Skip to content

Commit

Permalink
Traps INT signal (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudgg committed Sep 10, 2013
1 parent f9929f7 commit 3162761
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/listen/listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def initialize(*args, &block)
# for changes. The current thread is not blocked after starting.
#
def start
_signals_trap
_init_actors
unpause
adapter.async.start
Expand Down Expand Up @@ -81,6 +82,12 @@ def _init_actors
Celluloid::Actor[:listen_record] = Record.new(self)
end

def _signals_trap
if Signal.list.keys.include?('INT')
Signal.trap('INT') { exit }
end
end

def _build_record_if_needed
record && record.build
end
Expand Down
5 changes: 5 additions & 0 deletions spec/lib/listen/listener_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
adapter.stub_chain(:async, :start)
}

it "traps INT signal" do
expect(Signal).to receive(:trap).with('INT')
listener.start
end

it "registers change_pool" do
Listen::Change.should_receive(:pool).with(args: listener) { change_pool }
Celluloid::Actor.should_receive(:[]=).with(:listen_change_pool, change_pool)
Expand Down

0 comments on commit 3162761

Please sign in to comment.