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



66
67
68
# File 'lib/simple_apm.rb', line 66

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

.start!Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/simple_apm.rb', line 69

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