Class: GrubY::TDLib::ClientManager
- Inherits:
-
Object
- Object
- GrubY::TDLib::ClientManager
- Defined in:
- lib/gruubY/tdlib/client_manager.rb
Instance Attribute Summary collapse
-
#tdjson ⇒ Object
readonly
Returns the value of attribute tdjson.
Instance Method Summary collapse
- #add_client(client) ⇒ Object
- #close ⇒ Object
- #each_client(&block) ⇒ Object
-
#initialize(lib_path: nil, verbosity: 1) ⇒ ClientManager
constructor
A new instance of ClientManager.
- #remove_client(client) ⇒ Object
Constructor Details
#initialize(lib_path: nil, verbosity: 1) ⇒ ClientManager
Returns a new instance of ClientManager.
9 10 11 12 13 |
# File 'lib/gruubY/tdlib/client_manager.rb', line 9 def initialize(lib_path: nil, verbosity: 1) @tdjson = TdJson.new(lib_path: lib_path, verbosity: verbosity) @clients = {} @mutex = Mutex.new end |
Instance Attribute Details
#tdjson ⇒ Object (readonly)
Returns the value of attribute tdjson.
7 8 9 |
# File 'lib/gruubY/tdlib/client_manager.rb', line 7 def tdjson @tdjson end |
Instance Method Details
#add_client(client) ⇒ Object
15 16 17 18 19 |
# File 'lib/gruubY/tdlib/client_manager.rb', line 15 def add_client(client) key = client.native_client_key @mutex.synchronize { @clients[key] = client } client end |
#close ⇒ Object
31 32 33 34 |
# File 'lib/gruubY/tdlib/client_manager.rb', line 31 def close each_client(&:stop) true end |
#each_client(&block) ⇒ Object
26 27 28 29 |
# File 'lib/gruubY/tdlib/client_manager.rb', line 26 def each_client(&block) snapshot = @mutex.synchronize { @clients.values.dup } snapshot.each(&block) end |
#remove_client(client) ⇒ Object
21 22 23 24 |
# File 'lib/gruubY/tdlib/client_manager.rb', line 21 def remove_client(client) key = client.native_client_key @mutex.synchronize { @clients.delete(key) } end |