listen 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b027cf8c04a390cc6b96926228e2fff2eef7a47c
4
- data.tar.gz: 9f3ed4ac9ac99325d33240d33284e1aaaad2c25e
3
+ metadata.gz: 55c535918103e5c68a1ea42d8cb360db013ea539
4
+ data.tar.gz: 44764113825c9c554731d7141a7bcf1adeee0a06
5
5
  SHA512:
6
- metadata.gz: 153f0804b8dc9a45a257d017e13ad22b3ca480c28b574adc2ed4dd5584e81f9aaf6a0000ae7c042f1a1b80f99cb160e94a13a4c434b37745d711ff77e3d4fd67
7
- data.tar.gz: 4e0f61e9594c92772e9123eef689a176ac65a9fb26539275363146b7b58a06cf47a15af8ffc577170720328b68230831536e64368416dd5618898f15829af9d1
6
+ metadata.gz: 7259fce77dca1a6ff722521e34680ada567d4e7a948c85b09614787ed717ada197ad1b254d44222d6002b522066220365c99832468955d1a1201fc12d24234e2
7
+ data.tar.gz: 1ebb8207f946f7b2544466f0543164c872fc715f4cb8535579ca7e4944eb44d332b6415d95c2a0b1aec908d1fd091a080dd276f86af3de28020da2ad27ff8941
@@ -43,11 +43,8 @@ module Listen
43
43
  # Terminates all Listen actors and kill the adapter.
44
44
  #
45
45
  def stop
46
- thread.kill
47
- Celluloid::Actor.kill(Celluloid::Actor[:listen_adapter])
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') { exit }
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 raise an execption: #{$!}"
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
@@ -1,3 +1,3 @@
1
1
  module Listen
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.4"
3
3
  end
@@ -13,7 +13,13 @@ describe "Listen" do
13
13
  @listener = setup_listener(options, callback)
14
14
  @listener.start
15
15
  }
16
- after { listener.stop }
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 raise an execption: foo")
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(kill: true) }
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 "terminates record" do
156
- expect(record).to receive(:terminate)
132
+ it "joins thread" do
133
+ expect(thread).to receive(:join)
157
134
  listener.stop
158
135
  end
159
136
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Listen do
4
4
  describe '#to' do
5
- it "initalizes listner" do
5
+ it "initalizes listener" do
6
6
  expect(Listen::Listener).to receive(:new).with('/path')
7
7
  described_class.to('/path')
8
8
  end
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.3
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-09 00:00:00.000000000 Z
11
+ date: 2013-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid