Class: OnyxCord::Internal::EventExecutor::AsyncPool
- Inherits:
-
Object
- Object
- OnyxCord::Internal::EventExecutor::AsyncPool
- Defined in:
- lib/onyxcord/internal/event_executor.rb
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
-
#initialize(size:, queue_size: nil) ⇒ AsyncPool
constructor
rubocop:disable Lint/UnusedMethodArgument.
- #post(&block) ⇒ Object
- #queue_size ⇒ Object
- #shutdown ⇒ Object
- #threads ⇒ Object
Constructor Details
#initialize(size:, queue_size: nil) ⇒ AsyncPool
rubocop:disable Lint/UnusedMethodArgument
96 97 98 99 100 101 102 103 104 |
# File 'lib/onyxcord/internal/event_executor.rb', line 96 def initialize(size:, queue_size: nil) # rubocop:disable Lint/UnusedMethodArgument raise ArgumentError, 'Pool size must be greater than zero' unless size.positive? @size = size @queue = ::Async::Queue.new @closed = false @workers = [] start_workers end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
94 95 96 |
# File 'lib/onyxcord/internal/event_executor.rb', line 94 def queue @queue end |
Instance Method Details
#post(&block) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/onyxcord/internal/event_executor.rb', line 106 def post(&block) raise ArgumentError, 'EventExecutor::AsyncPool#post requires a block' unless block raise 'Event executor has been shut down' if @closed @queue.enqueue(block) end |
#queue_size ⇒ Object
113 114 115 |
# File 'lib/onyxcord/internal/event_executor.rb', line 113 def queue_size @queue.size end |
#shutdown ⇒ Object
117 118 119 120 121 122 |
# File 'lib/onyxcord/internal/event_executor.rb', line 117 def shutdown return if @closed @closed = true @size.times { @queue.enqueue(STOP) } end |
#threads ⇒ Object
124 125 126 |
# File 'lib/onyxcord/internal/event_executor.rb', line 124 def threads [] end |