class Concurrent::ImmediateExecutor
An executor service which runs all operations on the current thread, blocking as necessary. Operations are performed in the order they are received and no two operations can be performed simultaneously.
This executor service exists mainly for testing an debugging. When used it immediately runs every ‘#post` operation on the current thread, blocking that thread until the operation is complete. This can be very beneficial during testing because it makes all operations deterministic.
@note Intended for use primarily in testing and debugging.
Public Class Methods
Source
# File lib/concurrent-ruby/concurrent/executor/immediate_executor.rb, line 21 def initialize @stopped = Concurrent::Event.new end
Creates a new executor
Public Instance Methods
Source
# File lib/concurrent-ruby/concurrent/executor/immediate_executor.rb, line 34 def <<(task) post(&task) self end
@!macro executor_service_method_left_shift
Source
# File lib/concurrent-ruby/concurrent/executor/immediate_executor.rb, line 26 def post(*args, &task) raise ArgumentError.new('no block given') unless block_given? return false unless running? task.call(*args) true end
@!macro executor_service_method_post
Source
# File lib/concurrent-ruby/concurrent/executor/immediate_executor.rb, line 40 def running? ! shutdown? end
@!macro executor_service_method_running_question
Source
# File lib/concurrent-ruby/concurrent/executor/immediate_executor.rb, line 55 def shutdown @stopped.set true end
@!macro executor_service_method_shutdown
Source
# File lib/concurrent-ruby/concurrent/executor/immediate_executor.rb, line 50 def shutdown? @stopped.set? end
@!macro executor_service_method_shutdown_question
Source
# File lib/concurrent-ruby/concurrent/executor/immediate_executor.rb, line 45 def shuttingdown? false end
@!macro executor_service_method_shuttingdown_question
Source
# File lib/concurrent-ruby/concurrent/executor/immediate_executor.rb, line 62 def wait_for_termination(timeout = nil) @stopped.wait(timeout) end
@!macro executor_service_method_wait_for_termination