Class: TD::UpdateManager
- Inherits:
-
Object
- Object
- TD::UpdateManager
- Defined in:
- lib/tdlib/update_manager.rb
Constant Summary collapse
- TIMEOUT =
30
Instance Method Summary collapse
- #add_handler(handler) ⇒ Object (also: #<<)
-
#initialize(td_client) ⇒ UpdateManager
constructor
A new instance of UpdateManager.
- #run(callback: nil) ⇒ Object
Constructor Details
#initialize(td_client) ⇒ UpdateManager
Returns a new instance of UpdateManager.
4 5 6 7 8 |
# File 'lib/tdlib/update_manager.rb', line 4 def initialize(td_client) @td_client = td_client @handlers = Concurrent::Array.new @mutex = Mutex.new end |
Instance Method Details
#add_handler(handler) ⇒ Object Also known as: <<
10 11 12 |
# File 'lib/tdlib/update_manager.rb', line 10 def add_handler(handler) @mutex.synchronize { @handlers << handler } end |
#run(callback: nil) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/tdlib/update_manager.rb', line 16 def run(callback: nil) Thread.start do catch(:client_closed) { loop { handle_update(callback: callback); sleep 0.001 } } @mutex.synchronize { @handlers = [] } end end |