Class: Marquise::Janitor
- Inherits:
-
Object
- Object
- Marquise::Janitor
- Defined in:
- lib/marquise.rb
Overview
A helper class to cleanup Marquise consumers. We can’t just do the obvious, which would be to create a Proc inside ‘Marquise.initialize`, because that would leave a reference to the object laying around and we’d never get GC’d. So we do this instead. I stole this technique from Tempfile; blame them if this is insane.
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(ptr, conns) ⇒ Janitor
constructor
A new instance of Janitor.
Constructor Details
#initialize(ptr, conns) ⇒ Janitor
Returns a new instance of Janitor.
180 181 182 183 |
# File 'lib/marquise.rb', line 180 def initialize(ptr, conns) @ptr = ptr @conns = conns end |
Instance Method Details
#call(*args) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/marquise.rb', line 185 def call(*args) $stderr.puts "Janitor is running for #{@ptr.inspect}/#{@conns.inspect}" if $DEBUG @conns.values.each do |c| $stderr.puts "Pre-clean #{c.inspect}" if $DEBUG Marquise::FFI.marquise_close(c) $stderr.puts "Post-clean #{c.inspect}" if $DEBUG end $stderr.puts "Pre-clean #{@ptr.inspect}" if $DEBUG Marquise::FFI.marquise_consumer_shutdown(@ptr) $stderr.puts "Cleaned up #{@ptr.inspect} and #{@conns.inspect}" if $DEBUG end |