tdlib-ruby 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog.md +4 -0
- data/lib/tdlib-ruby.rb +0 -1
- data/lib/tdlib/client.rb +27 -13
- data/lib/tdlib/update_manager.rb +3 -1
- data/lib/tdlib/version.rb +1 -1
- data/spec/integration/tdlib_spec.rb +12 -0
- data/tdlib-ruby.gemspec +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7668dcf652a419af320628d4452b980fcc6b14d
|
4
|
+
data.tar.gz: bdc0bbe0e4bb6a1d9b4035ac8ac620d19e5105f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8886e255f1410795e460fe2d39b099c88c7f4e4c1dabea0bc16eaba1cd120720a185dba71e076063e84b3d01073e07063bf1b41ea4ad77efe3cf81151e55b1fe
|
7
|
+
data.tar.gz: 4d14e17af82aef8a6e9ce58e5332f3f20a74c3e25434a04c3946f22e442aea8ceb3c568111b7f83bde1f6923dfdc5f5d54521dd396da6906e7df492b5b227aa3
|
data/ChangeLog.md
CHANGED
data/lib/tdlib-ruby.rb
CHANGED
data/lib/tdlib/client.rb
CHANGED
@@ -58,7 +58,7 @@
|
|
58
58
|
#
|
59
59
|
# p @me
|
60
60
|
class TD::Client
|
61
|
-
TIMEOUT =
|
61
|
+
TIMEOUT = 20
|
62
62
|
|
63
63
|
def initialize(td_client = TD::Api.client_create,
|
64
64
|
update_manager = TD::UpdateManager.new(td_client),
|
@@ -66,7 +66,8 @@ class TD::Client
|
|
66
66
|
@td_client = td_client
|
67
67
|
@update_manager = update_manager
|
68
68
|
@config = TD.config.client.to_h.merge(extra_config)
|
69
|
-
@
|
69
|
+
@ready_condition_mutex = Mutex.new
|
70
|
+
@ready_condition = ConditionVariable.new
|
70
71
|
authorize
|
71
72
|
@update_manager.run
|
72
73
|
end
|
@@ -92,15 +93,25 @@ class TD::Client
|
|
92
93
|
# @param [Hash] query
|
93
94
|
# @return [Hash]
|
94
95
|
def broadcast_and_receive(query, timeout: TIMEOUT)
|
95
|
-
condition =
|
96
|
+
condition = ConditionVariable.new
|
96
97
|
extra = TD::Utils.generate_extra(query)
|
97
|
-
|
98
|
+
result = nil
|
99
|
+
mutex = Mutex.new
|
100
|
+
handler = ->(update) do
|
101
|
+
next unless update['@extra'] == extra
|
102
|
+
mutex.synchronize do
|
103
|
+
result = update
|
104
|
+
condition.signal
|
105
|
+
end
|
106
|
+
end
|
98
107
|
@update_manager.add_handler(handler)
|
99
108
|
query['@extra'] = extra
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
109
|
+
mutex.synchronize do
|
110
|
+
TD::Api.client_send(@td_client, query)
|
111
|
+
condition.wait(mutex, timeout)
|
112
|
+
raise TD::TimeoutError if result.nil?
|
113
|
+
result
|
114
|
+
end
|
104
115
|
end
|
105
116
|
|
106
117
|
# Synchronously executes TDLib request
|
@@ -128,9 +139,10 @@ class TD::Client
|
|
128
139
|
end
|
129
140
|
|
130
141
|
def on_ready(timeout: TIMEOUT, &_)
|
131
|
-
|
132
|
-
|
133
|
-
|
142
|
+
@ready_condition_mutex.synchronize do
|
143
|
+
return(yield self) if @ready || (@ready_condition.wait(@ready_condition_mutex, timeout) && @ready)
|
144
|
+
raise TD::TimeoutError
|
145
|
+
end
|
134
146
|
end
|
135
147
|
|
136
148
|
# Stops update manager and destroys TDLib client
|
@@ -163,8 +175,10 @@ class TD::Client
|
|
163
175
|
broadcast(encryption_key_query)
|
164
176
|
else
|
165
177
|
@update_manager.remove_handler(handler)
|
166
|
-
@
|
167
|
-
|
178
|
+
@ready_condition_mutex.synchronize do
|
179
|
+
@ready = true
|
180
|
+
@ready_condition.broadcast
|
181
|
+
end
|
168
182
|
end
|
169
183
|
end
|
170
184
|
@update_manager.add_handler(handler)
|
data/lib/tdlib/update_manager.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class TD::UpdateManager
|
2
|
+
TIMEOUT = 30
|
3
|
+
|
2
4
|
attr_reader :handlers
|
3
5
|
|
4
6
|
def initialize(td_client)
|
@@ -34,7 +36,7 @@ class TD::UpdateManager
|
|
34
36
|
private
|
35
37
|
|
36
38
|
def handle_update
|
37
|
-
update = TD::Api.client_receive(@td_client,
|
39
|
+
update = TD::Api.client_receive(@td_client, TIMEOUT)
|
38
40
|
@mutex.synchronize do
|
39
41
|
@handlers.each { |h| h.call(update) } unless update.nil?
|
40
42
|
end
|
data/lib/tdlib/version.rb
CHANGED
@@ -22,6 +22,12 @@ describe TD::Client do
|
|
22
22
|
|
23
23
|
it { is_expected.to include(client) }
|
24
24
|
it { is_expected.to include('ready') }
|
25
|
+
|
26
|
+
context 'when timeout reached' do
|
27
|
+
subject { client.on_ready(timeout: 0.0001) { [client, 'ready'] } }
|
28
|
+
|
29
|
+
it { expect { subject }.to raise_error(TD::TimeoutError) }
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
describe '#broadcast' do
|
@@ -46,6 +52,12 @@ describe TD::Client do
|
|
46
52
|
subject { client.on_ready { client.broadcast_and_receive(payload) } }
|
47
53
|
|
48
54
|
it { is_expected.to include('@type', 'entities') }
|
55
|
+
|
56
|
+
context 'when timeout reached' do
|
57
|
+
subject { client.on_ready(timeout: 0.0001) { client.broadcast_and_receive(payload) } }
|
58
|
+
|
59
|
+
it { expect { subject }.to raise_error(TD::TimeoutError) }
|
60
|
+
end
|
49
61
|
end
|
50
62
|
|
51
63
|
describe '#on' do
|
data/tdlib-ruby.gemspec
CHANGED
@@ -30,7 +30,6 @@ Gem::Specification.new do |gem|
|
|
30
30
|
gem.require_paths = ['lib']
|
31
31
|
|
32
32
|
gem.add_runtime_dependency 'dry-configurable', '~> 0.7'
|
33
|
-
gem.add_runtime_dependency 'celluloid', '~> 0.17'
|
34
33
|
|
35
34
|
gem.add_development_dependency 'bundler', '~> 1.10'
|
36
35
|
gem.add_development_dependency 'rake', '12.3.1'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tdlib-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Southbridge
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04
|
11
|
+
date: 2018-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.7'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: celluloid
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.17'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.17'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|