Module: Concurrent::RubyExecutor
- Included in:
- RubySingleThreadExecutor, RubyThreadPoolExecutor, TimerSet, TimerTask
- Defined in:
- lib/concurrent/executor/executor.rb
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.
41 42 43 44 |
# File 'lib/concurrent/executor/executor.rb', line 41 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.
83 84 85 86 87 88 89 90 91 |
# File 'lib/concurrent/executor/executor.rb', line 83 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.
27 28 29 30 31 32 33 34 |
# File 'lib/concurrent/executor/executor.rb', line 27 def post(*args, &task) raise ArgumentError.new('no block given') unless block_given? mutex.synchronize do return false unless running? execute(*args, &task) true end end |
#running? ⇒ Boolean
Is the executor running?
49 50 51 |
# File 'lib/concurrent/executor/executor.rb', line 49 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.
70 71 72 73 74 75 76 77 |
# File 'lib/concurrent/executor/executor.rb', line 70 def shutdown mutex.synchronize do break unless running? stop_event.set shutdown_execution end true end |
#shutdown? ⇒ Boolean
Is the executor shutdown?
63 64 65 |
# File 'lib/concurrent/executor/executor.rb', line 63 def shutdown? stopped_event.set? end |
#shuttingdown? ⇒ Boolean
Is the executor shuttingdown?
56 57 58 |
# File 'lib/concurrent/executor/executor.rb', line 56 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.
102 103 104 |
# File 'lib/concurrent/executor/executor.rb', line 102 def wait_for_termination(timeout = nil) stopped_event.wait(timeout) end |