Class: Concurrent::ImmediateExecutor
- Inherits:
-
AbstractExecutorService
- Object
- Synchronization::LockableObject
- AbstractExecutorService
- Concurrent::ImmediateExecutor
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
Overview
Intended for use primarily in testing and debugging.
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.
Direct Known Subclasses
Constant Summary
Constants inherited from AbstractExecutorService
AbstractExecutorService::FALLBACK_POLICIES
Instance Method Summary collapse
-
#<<(task) ⇒ self
Submit a task to the executor for asynchronous processing.
-
#initialize ⇒ ImmediateExecutor
constructor
Creates a new executor.
-
#post(*args) { ... } ⇒ Boolean
Submit a task to the executor for asynchronous processing.
-
#running? ⇒ Boolean
Is the executor running?.
-
#shutdown ⇒ Object
(also: #kill)
Begin an orderly shutdown.
-
#shutdown? ⇒ Boolean
Is the executor shutdown?.
-
#shuttingdown? ⇒ Boolean
Is the executor shuttingdown?.
-
#wait_for_termination(timeout = nil) ⇒ Boolean
Block until executor shutdown is complete or until ‘timeout` seconds have passed.
Constructor Details
#initialize ⇒ ImmediateExecutor
Creates a new executor
21 22 23 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb', line 21 def initialize @stopped = Concurrent::Event.new end |
Instance Method Details
#<<(task) ⇒ self
Submit a task to the executor for asynchronous processing.
34 35 36 37 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb', line 34 def <<(task) post(&task) self end |
#post(*args) { ... } ⇒ Boolean
Submit a task to the executor for asynchronous processing.
26 27 28 29 30 31 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/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 |
#running? ⇒ Boolean
Is the executor running?
40 41 42 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb', line 40 def running? ! shutdown? end |
#shutdown ⇒ Object Also known as: kill
Begin an orderly shutdown. Tasks already in the queue will be executed, but no new tasks will be accepted. Has no additional effect if the thread pool is not running.
55 56 57 58 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb', line 55 def shutdown @stopped.set true end |
#shutdown? ⇒ Boolean
Is the executor shutdown?
50 51 52 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb', line 50 def shutdown? @stopped.set? end |
#shuttingdown? ⇒ Boolean
Is the executor shuttingdown?
45 46 47 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb', line 45 def shuttingdown? false end |
#wait_for_termination(timeout = nil) ⇒ Boolean
Does not initiate shutdown or termination. Either ‘shutdown` or `kill` must be called before this method (or on another thread).
Block until executor shutdown is complete or until ‘timeout` seconds have passed.
62 63 64 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb', line 62 def wait_for_termination(timeout = nil) @stopped.wait(timeout) end |