listen 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/listen/listener.rb +16 -7
- data/lib/listen/version.rb +1 -1
- data/spec/acceptance/listen_spec.rb +8 -2
- data/spec/lib/listen/listener_spec.rb +4 -27
- data/spec/lib/listen_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55c535918103e5c68a1ea42d8cb360db013ea539
|
4
|
+
data.tar.gz: 44764113825c9c554731d7141a7bcf1adeee0a06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7259fce77dca1a6ff722521e34680ada567d4e7a948c85b09614787ed717ada197ad1b254d44222d6002b522066220365c99832468955d1a1201fc12d24234e2
|
7
|
+
data.tar.gz: 1ebb8207f946f7b2544466f0543164c872fc715f4cb8535579ca7e4944eb44d332b6415d95c2a0b1aec908d1fd091a080dd276f86af3de28020da2ad27ff8941
|
data/lib/listen/listener.rb
CHANGED
@@ -43,11 +43,8 @@ module Listen
|
|
43
43
|
# Terminates all Listen actors and kill the adapter.
|
44
44
|
#
|
45
45
|
def stop
|
46
|
-
|
47
|
-
|
48
|
-
Celluloid::Actor[:listen_silencer].terminate
|
49
|
-
Celluloid::Actor[:listen_change_pool].terminate
|
50
|
-
Celluloid::Actor[:listen_record].terminate
|
46
|
+
@stopping = true
|
47
|
+
thread.join
|
51
48
|
end
|
52
49
|
|
53
50
|
# Pauses listening callback (adapter still running)
|
@@ -124,20 +121,25 @@ module Listen
|
|
124
121
|
|
125
122
|
def _signals_trap
|
126
123
|
if Signal.list.keys.include?('INT')
|
127
|
-
Signal.trap('INT') {
|
124
|
+
Signal.trap('INT') { stop }
|
128
125
|
end
|
129
126
|
end
|
130
127
|
|
131
128
|
def _wait_for_changes
|
132
129
|
loop do
|
130
|
+
break if @stopping
|
131
|
+
|
133
132
|
changes = _pop_changes
|
134
133
|
unless changes.all? { |_,v| v.empty? }
|
135
134
|
block.call(changes[:modified], changes[:added], changes[:removed])
|
136
135
|
end
|
137
136
|
sleep 0.1
|
138
137
|
end
|
138
|
+
|
139
|
+
_terminate_celluloid_actors
|
140
|
+
exit
|
139
141
|
rescue => ex
|
140
|
-
Kernel.warn "[Listen warning]: Change block
|
142
|
+
Kernel.warn "[Listen warning]: Change block raised an exception: #{$!}"
|
141
143
|
Kernel.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
|
142
144
|
end
|
143
145
|
|
@@ -149,5 +151,12 @@ module Listen
|
|
149
151
|
end
|
150
152
|
changes.each { |_, v| v.uniq! }
|
151
153
|
end
|
154
|
+
|
155
|
+
def _terminate_celluloid_actors
|
156
|
+
Celluloid::Actor.kill(Celluloid::Actor[:listen_adapter])
|
157
|
+
Celluloid::Actor[:listen_silencer].terminate
|
158
|
+
Celluloid::Actor[:listen_change_pool].terminate
|
159
|
+
Celluloid::Actor[:listen_record].terminate
|
160
|
+
end
|
152
161
|
end
|
153
162
|
end
|
data/lib/listen/version.rb
CHANGED
@@ -13,7 +13,13 @@ describe "Listen" do
|
|
13
13
|
@listener = setup_listener(options, callback)
|
14
14
|
@listener.start
|
15
15
|
}
|
16
|
-
after {
|
16
|
+
after {
|
17
|
+
begin
|
18
|
+
listener.stop
|
19
|
+
rescue SystemExit
|
20
|
+
# ignore the SystemExit error from the thread
|
21
|
+
end
|
22
|
+
}
|
17
23
|
|
18
24
|
context "with one listen dir" do
|
19
25
|
let(:paths) { Pathname.new(Dir.pwd) }
|
@@ -23,7 +29,7 @@ describe "Listen" do
|
|
23
29
|
let(:callback) { ->(x,y,z) { raise 'foo' } }
|
24
30
|
|
25
31
|
it "warns the backtrace" do
|
26
|
-
expect(Kernel).to receive(:warn).with("[Listen warning]: Change block
|
32
|
+
expect(Kernel).to receive(:warn).with("[Listen warning]: Change block raised an exception: foo")
|
27
33
|
expect(Kernel).to receive(:warn).with(/^Backtrace:.*/)
|
28
34
|
listen { touch 'file.rb' }
|
29
35
|
end
|
@@ -126,34 +126,11 @@ describe Listen::Listener do
|
|
126
126
|
end
|
127
127
|
|
128
128
|
describe "#stop" do
|
129
|
-
let(:thread) { double(
|
130
|
-
before {
|
131
|
-
Celluloid::Actor.stub(:kill)
|
132
|
-
listener.stub(:thread) { thread }
|
133
|
-
}
|
134
|
-
|
135
|
-
it "kills thread" do
|
136
|
-
expect(thread).to receive(:kill)
|
137
|
-
listener.stop
|
138
|
-
end
|
139
|
-
|
140
|
-
it "terminates silencer" do
|
141
|
-
expect(silencer).to receive(:terminate)
|
142
|
-
listener.stop
|
143
|
-
end
|
144
|
-
|
145
|
-
it "kills adapter" do
|
146
|
-
expect(Celluloid::Actor).to receive(:kill).with(adapter)
|
147
|
-
listener.stop
|
148
|
-
end
|
149
|
-
|
150
|
-
it "terminates change_pool" do
|
151
|
-
expect(change_pool).to receive(:terminate)
|
152
|
-
listener.stop
|
153
|
-
end
|
129
|
+
let(:thread) { double(join: true) }
|
130
|
+
before { listener.stub(:thread) { thread } }
|
154
131
|
|
155
|
-
it "
|
156
|
-
expect(
|
132
|
+
it "joins thread" do
|
133
|
+
expect(thread).to receive(:join)
|
157
134
|
listener.stop
|
158
135
|
end
|
159
136
|
end
|
data/spec/lib/listen_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: listen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibaud Guillaume-Gentil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|