Class: Marquise::Janitor

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(ptr, conns) ⇒ Janitor

Returns a new instance of Janitor.



190
191
192
193
# File 'lib/marquise.rb', line 190

def initialize(ptr, conns)
  @ptr = ptr
  @conns = conns
end

Instance Method Details

#call(*args) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
# File 'lib/marquise.rb', line 195

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