Class: Aws::S3::DefaultExecutor Private
- Inherits:
-
Object
- Object
- Aws::S3::DefaultExecutor
- Defined in:
- lib/aws-sdk-s3/default_executor.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- DEFAULT_MAX_THREADS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
10- RUNNING =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:running- SHUTTING_DOWN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:shutting_down- SHUTDOWN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:shutdown
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ DefaultExecutor
constructor
private
A new instance of DefaultExecutor.
-
#kill ⇒ Boolean
private
Immediately terminates all worker threads and clears pending tasks.
-
#post(*args, &block) ⇒ Boolean
private
Submits a task for execution.
-
#shutdown(timeout = nil) ⇒ Boolean
private
Gracefully shuts down the executor, optionally with a timeout.
Constructor Details
#initialize(options = {}) ⇒ DefaultExecutor
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of DefaultExecutor.
12 13 14 15 16 17 18 |
# File 'lib/aws-sdk-s3/default_executor.rb', line 12 def initialize( = {}) @max_threads = [:max_threads] || DEFAULT_MAX_THREADS @state = RUNNING @queue = Queue.new @pool = [] @mutex = Mutex.new end |
Instance Method Details
#kill ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Immediately terminates all worker threads and clears pending tasks. This is a forceful shutdown that doesn’t wait for running tasks to complete.
38 39 40 41 42 43 44 45 46 |
# File 'lib/aws-sdk-s3/default_executor.rb', line 38 def kill @mutex.synchronize do @state = SHUTDOWN @pool.each(&:kill) @pool.clear @queue.clear end true end |
#post(*args, &block) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Submits a task for execution.
24 25 26 27 28 29 30 31 32 |
# File 'lib/aws-sdk-s3/default_executor.rb', line 24 def post(*args, &block) @mutex.synchronize do raise 'Executor has been shutdown and is no longer accepting tasks' unless @state == RUNNING @queue << [args, block] ensure_worker_available end true end |
#shutdown(timeout = nil) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Gracefully shuts down the executor, optionally with a timeout. Stops accepting new tasks and waits for running tasks to complete.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/aws-sdk-s3/default_executor.rb', line 54 def shutdown(timeout = nil) @mutex.synchronize do return true if @state == SHUTDOWN @state = SHUTTING_DOWN @pool.size.times { @queue << :shutdown } end if timeout deadline = Time.now + timeout @pool.each do |thread| remaining = deadline - Time.now break if remaining <= 0 thread.join([remaining, 0].max) end @pool.select(&:alive?).each(&:kill) else @pool.each(&:join) end @mutex.synchronize do @pool.clear @state = SHUTDOWN end true end |