tdlib-ruby 0.3.0 → 0.4.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: c2e11ed2e37f6949476c1b50f69f754692ff91fb
4
- data.tar.gz: 25639d93e2f8d29e0ef3283dcddd3b31a8e1fbb2
3
+ metadata.gz: '048a775eb8c8d07edb85a39c335d9ff33b5d8032'
4
+ data.tar.gz: a5b940f2431cf9dffd76fa41775dddc37fc0cfe4
5
5
  SHA512:
6
- metadata.gz: 748462dfb42dc3ae79dbc2099af326270184a41641c9545961650f868088d3fe3b0cf02cd626ad3f1511511d0311f52088fdba8a54e7060d1ddfcd55bdea5e3b
7
- data.tar.gz: c31362d10969c1eba778bb63fc62526c6ed80b73afc57309adcedd3896dab81914bc67dd4499818eaa919f10a4e5fbd6a1b8f0e5cdb39d03e0ec844ffbc8abae
6
+ metadata.gz: 74503569ec06caf882341062c719e32bcbc3715f02a638993800f1e9ec151685b483e7c7152b36e77327f6cd2ea2e135dacbee7412c07b4169b5939481c1c8eb
7
+ data.tar.gz: a28c24da2eae0d59313ecd4f6e9de9336a243747da8d6d266143463e8a4d185c745899c450148da65715b02ed122afd694d754947f538df002691a1a4e5c5ccf
@@ -1,4 +1,9 @@
1
- ### 0.3.0 / 2018-02-16
1
+ ### 0.4.0 / 2018-04-12
2
+
3
+ * Add configurable timeout
4
+ * Fix hanging threads after timeout
5
+
6
+ ### 0.3.0 / 2018-04-04
2
7
 
3
8
  * Use Concurrent::Promise instead of timeout module
4
9
  * Add integration tests
@@ -60,7 +60,7 @@
60
60
  class TD::Client
61
61
  include Concurrent
62
62
 
63
- TIMEOUT = 20
63
+ TIMEOUT = 10
64
64
 
65
65
  def initialize(td_client = TD::Api.client_create,
66
66
  update_manager = TD::UpdateManager.new(td_client),
@@ -91,7 +91,7 @@ class TD::Client
91
91
  # Sends asynchronous request to the TDLib client and returns received update synchronously
92
92
  # @param [Hash] query
93
93
  # @return [Hash]
94
- def broadcast_and_receive(query)
94
+ def broadcast_and_receive(query, timeout: TIMEOUT)
95
95
  result = nil
96
96
  extra = TD::Utils.generate_extra(query)
97
97
  handler = ->(update) { result = update if update['@extra'] == extra }
@@ -99,10 +99,11 @@ class TD::Client
99
99
  query['@extra'] = extra
100
100
  TD::Api.client_send(@td_client, query)
101
101
  promise = Promise.new do
102
- until result do end
102
+ time_start = Time.now
103
+ until result || Time.now - time_start > timeout do end
103
104
  result
104
105
  end
105
- promise.execute.value(TIMEOUT) || (raise TD::TimeoutError)
106
+ promise.execute.value(timeout) || (raise TD::TimeoutError)
106
107
  end
107
108
 
108
109
  # Synchronously executes TDLib request
@@ -129,8 +130,12 @@ class TD::Client
129
130
  @update_manager.add_handler(handler)
130
131
  end
131
132
 
132
- def on_ready(&_)
133
- raise TD::TimeoutError unless Promise.execute { until @ready do end }.then { self }.execute.value(TIMEOUT)
133
+ def on_ready(timeout: TIMEOUT, &_)
134
+ promise = Promise.new do
135
+ time_start = Time.now
136
+ until @ready || Time.now - time_start > timeout do end
137
+ end
138
+ raise TD::TimeoutError unless promise.execute.then { self }.execute.value(timeout)
134
139
  yield self
135
140
  end
136
141
 
@@ -4,7 +4,6 @@ class TD::UpdateManager
4
4
  def initialize(td_client)
5
5
  @td_client = td_client
6
6
  @handlers = []
7
- @handlers_for_removal = []
8
7
  @mutex = Mutex.new
9
8
  init_update_loop
10
9
  end
@@ -1,4 +1,4 @@
1
1
  module TD
2
2
  # tdlib-ruby version
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
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.3.0
4
+ version: 0.4.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-04 00:00:00.000000000 Z
11
+ date: 2018-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable