Class: TD::UpdateManager
- Inherits:
-
Object
- Object
- TD::UpdateManager
- Defined in:
- lib/tdlib/update_manager.rb
Instance Attribute Summary collapse
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
Instance Method Summary collapse
- #add_handler(handler) ⇒ Object
-
#initialize(td_client) ⇒ UpdateManager
constructor
A new instance of UpdateManager.
- #remove_handler(handler) ⇒ Object
- #run ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
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 = [] @mutex = Mutex.new end |
Instance Attribute Details
#handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
2 3 4 |
# File 'lib/tdlib/update_manager.rb', line 2 def handlers @handlers end |
Instance Method Details
#add_handler(handler) ⇒ Object
10 11 12 |
# File 'lib/tdlib/update_manager.rb', line 10 def add_handler(handler) @mutex.synchronize { @handlers << handler } end |
#remove_handler(handler) ⇒ Object
14 15 16 17 18 |
# File 'lib/tdlib/update_manager.rb', line 14 def remove_handler(handler) Thread.start do @mutex.synchronize { @handlers.delete(handler) } end end |
#run ⇒ Object
20 21 22 23 24 |
# File 'lib/tdlib/update_manager.rb', line 20 def run @update_loop_thread = Thread.start do loop { stopped? ? break : handle_update } end end |
#stop ⇒ Object
26 27 28 |
# File 'lib/tdlib/update_manager.rb', line 26 def stop @stopped = true end |
#stopped? ⇒ Boolean
30 31 32 |
# File 'lib/tdlib/update_manager.rb', line 30 def stopped? !!@stopped end |