Sha256: e5f91dd59f2c318082a8e2a6e7945aaa19d0a7f858b1e498d696b11d64d1f619
Contents?: true
Size: 735 Bytes
Versions: 3
Compression:
Stored size: 735 Bytes
Contents
class TD::UpdateManager attr_reader :handlers def initialize(td_client) @td_client = td_client @handlers = [] @mutex = Mutex.new end def add_handler(handler) @mutex.synchronize { @handlers << handler } end def remove_handler(handler) Thread.start do @mutex.synchronize { @handlers.delete(handler) } end end def run @update_loop_thread = Thread.start do loop { stopped? ? break : handle_update } end end def stop @stopped = true end def stopped? !!@stopped end private def handle_update update = TD::Api.client_receive(@td_client, 10) @mutex.synchronize do @handlers.each { |h| h.call(update) } unless update.nil? end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
tdlib-ruby-0.9.1 | lib/tdlib/update_manager.rb |
tdlib-ruby-0.9.0 | lib/tdlib/update_manager.rb |
tdlib-ruby-0.8.0 | lib/tdlib/update_manager.rb |