Class: GrubY::TDLib::ClientManager

Inherits:
Object
  • Object
show all
Defined in:
lib/gruubY/tdlib/client_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#tdjsonObject (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

#closeObject



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