Sha256: 986677d1f538027acbbbe1fe0bee2275a542dfdd2c987293cf5a45d51529209f

Contents?: true

Size: 671 Bytes

Versions: 20

Compression:

Stored size: 671 Bytes

Contents

module Mixpanel::Async
  WORKER_MUTEX = Mutex.new

  def worker
    WORKER_MUTEX.synchronize do
      @worker || (@worker = IO.popen(self.cmd, 'w'))
    end
  end

  def dispose_worker(w)
    WORKER_MUTEX.synchronize do
      if(@worker == w)
        @worker = nil
        w.close
      end
    end
  end
  
  protected
  
  def cmd
    @cmd || begin
      require 'escape'
      require 'rbconfig'
      interpreter = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"]
      subprocess = File.join(File.dirname(__FILE__), 'subprocess.rb')
      @cmd = Escape.shell_command([interpreter, subprocess])
    end
  end
    
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mixpanel-4.1.1 lib/mixpanel/async.rb
mixpanel-4.1.0 lib/mixpanel/async.rb
mixpanel-4.0.9 lib/mixpanel/async.rb
mixpanel-4.0.8 lib/mixpanel/async.rb
mixpanel-4.0.7 lib/mixpanel/async.rb
mixpanel-4.0.6 lib/mixpanel/async.rb
mixpanel-4.0.5 lib/mixpanel/async.rb
mixpanel-4.0.4 lib/mixpanel/async.rb
mixpanel-4.0.3 lib/mixpanel/async.rb
mixpanel-4.0.2 lib/mixpanel/async.rb
mixpanel-4.0.1 lib/mixpanel/async.rb
mixpanel-4.0.0 lib/mixpanel/async.rb
mixpanel-3.6.2 lib/mixpanel/async.rb
mixpanel-3.5.2 lib/mixpanel/async.rb
mixpanel-3.5.1 lib/mixpanel/async.rb
mixpanel-3.5.0 lib/mixpanel/async.rb
mixpanel-3.4.0 lib/mixpanel/async.rb
mixpanel-3.1.0 lib/mixpanel/async.rb
mixpanel-3.0.2 lib/mixpanel/async.rb
mixpanel-3.0.1 lib/mixpanel/async.rb