Module: Concurrent::RubyExecutor
- Included in:
- RubySingleThreadExecutor, RubyThreadPoolExecutor, TimerSet, TimerTask
- Defined in:
- lib/concurrent/executor/executor.rb
Constant Summary collapse
- FALLBACK_POLICIES =
The set of possible fallback policies that may be set at thread pool creation.
[:abort, :discard, :caller_runs]
Instance Attribute Summary
Attributes included from Executor
Instance Method Summary collapse
-
#<<(task) ⇒ self
Submit a task to the executor for asynchronous processing.
-
#kill ⇒ Object
Begin an immediate shutdown.
-
#post(*args) { ... } ⇒ Boolean
Submit a task to the executor for asynchronous processing.
-
#running? ⇒ Boolean
Is the executor running?.
-
#shutdown ⇒ Object
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.
Methods included from Logging
Methods included from Executor
Instance Method Details
#<<(task) ⇒ self
Submit a task to the executor for asynchronous processing.
128 129 130 131 |
# File 'lib/concurrent/executor/executor.rb', line 128 def <<(task) post(&task) self end |
#kill ⇒ Object
Begin an immediate shutdown. In-progress tasks will be allowed to complete but enqueued tasks will be dismissed and no new tasks will be accepted. Has no additional effect if the thread pool is not running.
180 181 182 183 184 185 186 187 188 |
# File 'lib/concurrent/executor/executor.rb', line 180 def kill mutex.synchronize do break if shutdown? stop_event.set kill_execution stopped_event.set end true end |
#post(*args) { ... } ⇒ Boolean
Submit a task to the executor for asynchronous processing.
111 112 113 114 115 116 117 118 119 |
# File 'lib/concurrent/executor/executor.rb', line 111 def post(*args, &task) raise ArgumentError.new('no block given') unless block_given? mutex.synchronize do # If the executor is shut down, reject this task return handle_fallback(*args, &task) unless running? execute(*args, &task) true end end |
#running? ⇒ Boolean
Is the executor running?
138 139 140 |
# File 'lib/concurrent/executor/executor.rb', line 138 def running? ! stop_event.set? end |
#shutdown ⇒ Object
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.
165 166 167 168 169 170 171 172 |
# File 'lib/concurrent/executor/executor.rb', line 165 def shutdown mutex.synchronize do break unless running? stop_event.set shutdown_execution end true end |
#shutdown? ⇒ Boolean
Is the executor shutdown?
156 157 158 |
# File 'lib/concurrent/executor/executor.rb', line 156 def shutdown? stopped_event.set? end |
#shuttingdown? ⇒ Boolean
Is the executor shuttingdown?
147 148 149 |
# File 'lib/concurrent/executor/executor.rb', line 147 def shuttingdown? ! (running? || shutdown?) 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.
201 202 203 |
# File 'lib/concurrent/executor/executor.rb', line 201 def wait_for_termination(timeout = nil) stopped_event.wait(timeout) end |