Class: ActionCable::Server::ThreadedExecutor
- Inherits:
-
Object
- Object
- ActionCable::Server::ThreadedExecutor
- Defined in:
- lib/action_cable/server/base.rb
Overview
A wrapper over ConcurrentRuby::ThreadPoolExecutor and Concurrent::TimerTask
Instance Method Summary collapse
-
#initialize(max_size: 10) ⇒ ThreadedExecutor
constructor
:nodoc:.
- #post(task = nil, &block) ⇒ Object
- #shutdown ⇒ Object
- #timer(interval, &block) ⇒ Object
Constructor Details
#initialize(max_size: 10) ⇒ ThreadedExecutor
:nodoc:
11 12 13 14 15 16 17 18 |
# File 'lib/action_cable/server/base.rb', line 11 def initialize(max_size: 10) @executor = Concurrent::ThreadPoolExecutor.new( name: "ActionCable server", min_threads: 1, max_threads: max_size, max_queue: 0, ) end |
Instance Method Details
#post(task = nil, &block) ⇒ Object
20 21 22 23 |
# File 'lib/action_cable/server/base.rb', line 20 def post(task = nil, &block) task ||= block @executor << task end |
#shutdown ⇒ Object
29 |
# File 'lib/action_cable/server/base.rb', line 29 def shutdown = @executor.shutdown |
#timer(interval, &block) ⇒ Object
25 26 27 |
# File 'lib/action_cable/server/base.rb', line 25 def timer(interval, &block) Concurrent::TimerTask.new(execution_interval: interval, &block).tap(&:execute) end |