tdlib-ruby 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9a09d6aacb86936097c8e639dea0ac3930cd4f8
4
- data.tar.gz: f5b25381a3aee0a60d45042115d943ac20b9242b
3
+ metadata.gz: f7668dcf652a419af320628d4452b980fcc6b14d
4
+ data.tar.gz: bdc0bbe0e4bb6a1d9b4035ac8ac620d19e5105f0
5
5
  SHA512:
6
- metadata.gz: ef289a28405f4267953819f2f626ece72ad5abf18b77ec989b5756197fd0e3715c44a00d4476c8603597d352ac9b0dc21302ebbffce8083e24ce78736a501865
7
- data.tar.gz: 7efb461c9258ce835a36f611c274155825d6492d93d7d6cff7d9a25399656091dc0bf2e1aaf3b4bc2f52363fd96f8f1dffd2be1a8a0ec82b876451b3578564f5
6
+ metadata.gz: 8886e255f1410795e460fe2d39b099c88c7f4e4c1dabea0bc16eaba1cd120720a185dba71e076063e84b3d01073e07063bf1b41ea4ad77efe3cf81151e55b1fe
7
+ data.tar.gz: 4d14e17af82aef8a6e9ce58e5332f3f20a74c3e25434a04c3946f22e442aea8ceb3c568111b7f83bde1f6923dfdc5f5d54521dd396da6906e7df492b5b227aa3
@@ -1,3 +1,7 @@
1
+ ### 0.9.2 / 2018-05-04
2
+
3
+ * Fix some potential deadlocks
4
+
1
5
  ### 0.9.1 / 2018-04-27
2
6
 
3
7
  * Fix deadlock in Client#on_ready
@@ -1,6 +1,5 @@
1
1
  require 'tdlib/version'
2
2
  require 'dry/configurable'
3
- require 'celluloid'
4
3
 
5
4
  module TD
6
5
  extend Dry::Configurable
@@ -58,7 +58,7 @@
58
58
  #
59
59
  # p @me
60
60
  class TD::Client
61
- TIMEOUT = 10
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
- @ready_condition = Celluloid::Condition.new
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 = Celluloid::Condition.new
96
+ condition = ConditionVariable.new
96
97
  extra = TD::Utils.generate_extra(query)
97
- handler = ->(update) { condition.signal(update) if update['@extra'] == extra }
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
- TD::Api.client_send(@td_client, query)
101
- condition.wait(timeout)
102
- rescue Celluloid::ConditionError
103
- raise TD::TimeoutError
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
- yield self if @ready || @ready_condition.wait(timeout)
132
- rescue Celluloid::ConditionError
133
- raise TD::TimeoutError
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
- @ready = true
167
- @ready_condition.signal(true)
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)
@@ -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, 10)
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
@@ -1,4 +1,4 @@
1
1
  module TD
2
2
  # tdlib-ruby version
3
- VERSION = "0.9.1"
3
+ VERSION = "0.9.2"
4
4
  end
@@ -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
@@ -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.1
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-27 00:00:00.000000000 Z
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