Class: MTProto::Async::RequestQueue
- Inherits:
-
Object
- Object
- MTProto::Async::RequestQueue
- Defined in:
- lib/mtproto/async/request_queue.rb
Instance Method Summary collapse
- #call(key:, &blk) ⇒ Object
-
#initialize ⇒ RequestQueue
constructor
A new instance of RequestQueue.
- #shutdown ⇒ Object
Constructor Details
#initialize ⇒ RequestQueue
Returns a new instance of RequestQueue.
8 9 10 11 12 |
# File 'lib/mtproto/async/request_queue.rb', line 8 def initialize @queues = Concurrent::Hash.new @threads = Concurrent::Hash.new @running = Concurrent::AtomicBoolean.new(true) end |
Instance Method Details
#call(key:, &blk) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/mtproto/async/request_queue.rb', line 14 def call(key:, &blk) ensure_worker_running!(key) future = Concurrent::Promises.resolvable_future @queues[key] << [blk, future] future end |
#shutdown ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/mtproto/async/request_queue.rb', line 22 def shutdown @running.make_false @threads.each_value do |thread| thread.join(2) thread.kill if thread.alive? end @threads.clear @queues.clear end |