Class: Swee::AppExecutor::ExeThread

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

Overview

TODO: 多线程处理控制器和路由

Constant Summary collapse

DEFAULT_SLEEP =
0.5

Instance Method Summary collapse

Constructor Details

#initializeExeThread

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

Returns:

  • (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

#runObject



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

#waitObject



118
119
120
# File 'lib/swee/app_executor.rb', line 118

def wait
  sleep DEFAULT_SLEEP
end