Class: Swee::AppExecutor::ExeThread
Overview
TODO: 多线程处理控制器和路由
Constant Summary collapse
- DEFAULT_SLEEP =
0.5
Instance Method Summary collapse
- #<<(mission) ⇒ Object
- #busy? ⇒ Boolean
- #create! ⇒ Object
-
#initialize ⇒ ExeThread
constructor
A new instance of ExeThread.
- #run ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize ⇒ ExeThread
Returns a new instance of ExeThread.
91 92 93 |
# File 'lib/swee/app_executor.rb', line 91 def initialize @mission_queue = [] end |
Instance Method Details
#<<(mission) ⇒ Object
113 114 115 116 |
# File 'lib/swee/app_executor.rb', line 113 def << mission @mission_queue << mission create! if @t.dead? end |
#busy? ⇒ Boolean
109 110 111 |
# File 'lib/swee/app_executor.rb', line 109 def busy? !@mission_queue.empty? end |
#create! ⇒ Object
105 106 107 |
# File 'lib/swee/app_executor.rb', line 105 def create! @t = Thread.new { run } end |
#run ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/swee/app_executor.rb', line 95 def run while true if @mission_queue.empty? wait else @mission_queue.shift.call() end end end |
#wait ⇒ Object
118 119 120 |
# File 'lib/swee/app_executor.rb', line 118 def wait sleep DEFAULT_SLEEP end |