-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cease holding references to listeners
The `@listeners` variable is global state that holds a reference to each `Listener` instance and can only be cleared by calling `Listen.stop`. This prevents individual listeners from being garbage collected if they are abandoned before `Listen.stop` is called. This commit replaces `@listeners` with a comparable call to `ObjectSpace.each_object`. Partially addresses #476.
- Loading branch information
1 parent
ba5059c
commit 694e28b
Showing
3 changed files
with
12 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
RSpec.describe Listen do | ||
let(:listener) { instance_double(Listen::Listener, stop: nil) } | ||
|
||
after do | ||
Listen.stop | ||
end | ||
|
||
describe '.to' do | ||
it 'initalizes listener' do | ||
expect(Listen::Listener).to receive(:new).with('/path') { listener } | ||
it 'initializes listener' do | ||
expect(Listen::Listener).to receive(:new).with('/path') | ||
described_class.to('/path') | ||
end | ||
end | ||
|
||
describe '.stop' do | ||
it 'stops all listeners' do | ||
allow(Listen::Listener).to receive(:new).with('/path') { listener } | ||
expect(listener).to receive(:stop) | ||
described_class.to('/path') | ||
Listen.stop | ||
expect(Listen::Listener.allocate).to receive(:stop) | ||
described_class.stop | ||
end | ||
end | ||
end |