tdlib-ruby 0.8.0 → 0.9.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ae3602c33ec3fcc94afe086dfa85572d59d851b
4
- data.tar.gz: 219b93cf45f05b909e276b6534b89be70a00f834
3
+ metadata.gz: c84fd6d3b63901223ca8b58a9bea70c0fb2cae9b
4
+ data.tar.gz: 154ea127f32e385caba187f87c23a117e98950b4
5
5
  SHA512:
6
- metadata.gz: 0f24b6e7d8c1821d00db49b1e45f653f040bb31e792cc46871c2789ba5e3f62de28f2eaa3a2921d3b0929ce502aa17f56093d44b26fe8044d9700c310b24429d
7
- data.tar.gz: 42ba3c0ba60e5b7ed0f51be08314e607adf2da3a22c64d0fbaf2a84ee573adfce2d09ac6f1e050152964e7cef5f52595ea33f62a316e5a0be4a36ee4a0492667
6
+ metadata.gz: fe38b4ed8eca764247be42b4dc66d45c7880ea15bdcba516923aa1668441b89f50c85ec46bcb6c085aa0a016618c44312c06f95b4f988bddbeb9335a751f4c34
7
+ data.tar.gz: 50c96aabe2d58139604c1f3590da3d8ac80723622cac02cfc64daa23f8af6d924da0be44a5e072dbd310f781ba1a6144332496d7984ff21959411271eced8db0
@@ -1,3 +1,6 @@
1
+ ### 0.9.0 / 2018-04-25
2
+ * Use Celluloid
3
+
1
4
  ### 0.8.0 / 2018-04-25
2
5
 
3
6
  * Fix await methods
@@ -1,5 +1,6 @@
1
1
  require 'tdlib/version'
2
2
  require 'dry/configurable'
3
+ require 'celluloid'
3
4
 
4
5
  module TD
5
6
  extend Dry::Configurable
@@ -58,8 +58,6 @@
58
58
  #
59
59
  # p @me
60
60
  class TD::Client
61
- include Concurrent
62
-
63
61
  TIMEOUT = 10
64
62
 
65
63
  def initialize(td_client = TD::Api.client_create,
@@ -68,6 +66,7 @@ class TD::Client
68
66
  @td_client = td_client
69
67
  @update_manager = update_manager
70
68
  @config = TD.config.client.to_h.merge(extra_config)
69
+ @ready = Celluloid::Condition.new
71
70
  authorize
72
71
  @update_manager.run
73
72
  end
@@ -93,19 +92,15 @@ class TD::Client
93
92
  # @param [Hash] query
94
93
  # @return [Hash]
95
94
  def broadcast_and_receive(query, timeout: TIMEOUT)
96
- result = nil
95
+ condition = Celluloid::Condition.new
97
96
  extra = TD::Utils.generate_extra(query)
98
- handler = ->(update) { result = update if update['@extra'] == extra }
97
+ handler = ->(update) { condition.signal(update) if update['@extra'] == extra }
99
98
  @update_manager.add_handler(handler)
100
99
  query['@extra'] = extra
101
100
  TD::Api.client_send(@td_client, query)
102
- time_start = Time.now
103
- loop do
104
- sleep 0.1
105
- break if result
106
- raise TD::TimeoutError if Time.now - time_start > timeout
107
- end
108
- result
101
+ condition.wait(timeout)
102
+ rescue Celluloid::ConditionError
103
+ raise TD::TimeoutError
109
104
  end
110
105
 
111
106
  # Synchronously executes TDLib request
@@ -133,13 +128,10 @@ class TD::Client
133
128
  end
134
129
 
135
130
  def on_ready(timeout: TIMEOUT, &_)
136
- time_start = Time.now
137
- loop do
138
- sleep 0.1
139
- break if @ready
140
- raise TD::TimeoutError if Time.now - time_start > timeout
141
- end
131
+ @ready.wait(timeout)
142
132
  yield self
133
+ rescue Celluloid::ConditionError
134
+ raise TD::TimeoutError
143
135
  end
144
136
 
145
137
  # Stops update manager and destroys TDLib client
@@ -172,7 +164,7 @@ class TD::Client
172
164
  broadcast(encryption_key_query)
173
165
  else
174
166
  @update_manager.remove_handler(handler)
175
- @ready = true
167
+ @ready.signal(true)
176
168
  end
177
169
  end
178
170
  @update_manager.add_handler(handler)
@@ -1,4 +1,4 @@
1
1
  module TD
2
2
  # tdlib-ruby version
3
- VERSION = "0.8.0"
3
+ VERSION = "0.9.0"
4
4
  end
@@ -36,7 +36,7 @@ describe TD::Client do
36
36
 
37
37
  it 'runs block on update' do
38
38
  subject
39
- sleep 3
39
+ sleep 1
40
40
  expect(@result).to include('@type', 'entities')
41
41
  end
42
42
  end
@@ -58,7 +58,7 @@ describe TD::Client do
58
58
 
59
59
  it 'runs block on update' do
60
60
  subject
61
- sleep 3
61
+ sleep 1
62
62
  expect(@result).to include('@type', 'entities')
63
63
  end
64
64
  end
@@ -30,7 +30,7 @@ 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 'concurrent-ruby', '~> 1.0'
33
+ gem.add_runtime_dependency 'celluloid', '~> 0.17'
34
34
 
35
35
  gem.add_development_dependency 'bundler', '~> 1.10'
36
36
  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.8.0
4
+ version: 0.9.0
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-25 00:00:00.000000000 Z
11
+ date: 2018-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
- name: concurrent-ruby
28
+ name: celluloid
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: '0.17'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.0'
40
+ version: '0.17'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -147,9 +147,7 @@ files:
147
147
  - lib/tdlib/version.rb
148
148
  - spec/integration/tdlib_spec.rb
149
149
  - spec/spec_helper.rb
150
- - spec/support/update_manager_stub.rb
151
150
  - spec/tdlib_spec.rb
152
- - spec/unit/client_spec.rb
153
151
  - tdlib-ruby.gemspec
154
152
  homepage: https://github.com/centosadmin/tdlib-ruby
155
153
  licenses:
@@ -178,6 +176,4 @@ summary: Ruby bindings and client for TDlib
178
176
  test_files:
179
177
  - spec/integration/tdlib_spec.rb
180
178
  - spec/spec_helper.rb
181
- - spec/support/update_manager_stub.rb
182
179
  - spec/tdlib_spec.rb
183
- - spec/unit/client_spec.rb
@@ -1,19 +0,0 @@
1
- class UpdateManagerStub
2
- attr_reader :handlers
3
-
4
- def initialize(td_client, update)
5
- @td_client, @update, @handlers = td_client, update, []
6
- end
7
-
8
- def run
9
- end
10
-
11
- def add_handler(handler)
12
- @handlers << handler
13
- handler.call(@update)
14
- end
15
-
16
- def remove_handler(handler)
17
- @handlers.delete(handler)
18
- end
19
- end
@@ -1,73 +0,0 @@
1
- require 'spec_helper'
2
- require 'tdlib-ruby'
3
- require 'support/update_manager_stub'
4
-
5
- Thread.abort_on_exception = true
6
-
7
- describe TD::Client do
8
- let(:client) { described_class.new(td_client, update_manager) }
9
- let(:td_client) { double }
10
- let(:update_manager) { UpdateManagerStub.new(td_client, update) }
11
- let(:query) { { '@type' => 'type' } }
12
- let(:send_result) { 'send_result' }
13
- let(:update) { { '@type' => 'update' } }
14
- let(:extra) { 'extra' }
15
-
16
- before do
17
- allow(TD::Api).to receive(:client_create).and_return(td_client)
18
- allow(TD::Api).to receive(:client_send).with(td_client, query).and_return(send_result)
19
- allow(TD::Api).to receive(:client_execute).with(td_client, query).and_return(send_result)
20
- allow(TD::Api).to receive(:client_receive).with(td_client).and_return(update)
21
-
22
- allow(TD::Utils).to receive(:generate_extra).with(query).and_return(extra)
23
- end
24
-
25
- describe '#broadcast' do
26
- context 'when no block given' do
27
- subject { client.broadcast(query) }
28
-
29
- it { is_expected.to eq(send_result) }
30
- end
31
-
32
- context 'when block given' do
33
- subject { client.broadcast(query) { |update| raise update.to_s } }
34
-
35
- it 'adds @extra key to query' do
36
- subject
37
- expect(query.keys).to include('@extra')
38
- end
39
-
40
- it { is_expected.to eq(send_result) }
41
- end
42
- end
43
-
44
- describe '#broadcast_and_receive' do
45
- let(:update) { { '@type' => 'update', '@extra' => extra } }
46
-
47
- subject { client.broadcast_and_receive(query) }
48
-
49
- it { is_expected.to eq(update) }
50
- end
51
-
52
- describe '#execute' do
53
- subject { client.execute(query) }
54
-
55
- it { is_expected.to eq(send_result) }
56
- end
57
-
58
- describe '#on' do
59
- subject { client.on('update') { |update| update } }
60
-
61
- context 'when update type matches passed type' do
62
- let(:update) { { '@type' => 'update', '@extra' => extra } }
63
-
64
- it { is_expected.to eq(update) }
65
- end
66
-
67
- context 'when update type does not match passed type' do
68
- let(:update) { { '@type' => 'not_update', '@extra' => extra } }
69
-
70
- it { is_expected.not_to eq(update) }
71
- end
72
- end
73
- end