Class: SimpleApm::ProcessingThread

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_apm.rb

Overview

开启一个接收事件的并行thread,每隔一秒处理一次

Class Method Summary collapse

Class Method Details

.add_event(e) ⇒ Object



73
74
75
# File 'lib/simple_apm.rb', line 73

def add_event(e)
  @processing_thread && @processing_thread[:events].push(e)
end

.start!Object



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/simple_apm.rb', line 76

def start!
  @main_thread ||= ::Thread.current
  @processing_thread ||= ::Thread.new do
    ::Thread.current.name = 'simple-apm-processing-thread' if ::Thread.current.respond_to?(:name)
    ::Thread.current[:events] ||= []
    loop do
      while e = ::Thread.current[:events].shift
        ::SimpleApm::Worker.process! e
      end
      sleep 0.5
    end
  end
end