grammerb 1.0.4-x86_64-linux → 1.0.5-x86_64-linux

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
  SHA256:
3
- metadata.gz: de4c36e0db14a91aa2b3cc35811743731a97f13139cd60c11db6a9002118c163
4
- data.tar.gz: 5ed42c40fd4328aa36f971761a48a973b94e9eed68ec6a3bca3a98ddd1b762ba
3
+ metadata.gz: 899d4c25734e75c00292b4c4776e7913e7447f33176c5b0be790c321009ba662
4
+ data.tar.gz: 1cc7a2c114ea01e1559b94d85ed845ea74041a6928ef68d891f6e42b4f25f6e0
5
5
  SHA512:
6
- metadata.gz: 7e77e4ac1c4f6a26fc16bf6a3b0407df178a19afff905b7eaad720a9343f5b3b18ee019c66d1f5609d123af1e24017175fea9bdbae1f1f029733373c21e6ea2d
7
- data.tar.gz: 3da1e392c7f9b3db9dbaacae7978a65d53ad952c06e019355b3ffc6a2e788b7983008fc6b6279e84962253d54b3cc14f637022b471d19f35488a340f32ed4865
6
+ metadata.gz: 1909108f0f63aaf52e2b621148e84301662a80728a8ecf4979038faa36f56ce091420a0e9e5c4f96bf08cfc63b7c87294af638a0a995a77266870086a3ee788b
7
+ data.tar.gz: e7d0b7dc3d4194285a9bf7a0fd570fff3554cb678426974572db3c6a5963fd49350994c3e26c3f4d1ee23dbaaae6c4b51ce28645f3da79fad17cb12f1aac34c2
Binary file
Binary file
Binary file
@@ -6,28 +6,42 @@ require "set"
6
6
  module Grammerb
7
7
  class HandlerPool
8
8
  def initialize(size)
9
+ @size = size
9
10
  @queue = Queue.new
10
- @workers = size.times.map do
11
- Thread.new do
12
- loop do
13
- task = @queue.pop
14
- break if task == :shutdown
15
- task.call
16
- rescue => e
17
- # Error handling is inside the task block itself
18
- end
19
- end
20
- end
11
+ @workers = nil
12
+ @mu = Mutex.new
21
13
  end
22
14
 
23
15
  def schedule(&block)
16
+ ensure_started
24
17
  @queue.push(block)
25
18
  end
26
19
 
27
20
  def shutdown
21
+ return unless @workers
28
22
  @workers.size.times { @queue.push(:shutdown) }
29
23
  @workers.each { |t| t.join(5) }
30
24
  end
25
+
26
+ private
27
+
28
+ def ensure_started
29
+ return if @workers
30
+ @mu.synchronize do
31
+ return if @workers
32
+ @workers = @size.times.map do
33
+ Thread.new do
34
+ loop do
35
+ task = @queue.pop
36
+ break if task == :shutdown
37
+ task.call
38
+ rescue => e
39
+ # Error handling is inside the task block itself
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
31
45
  end
32
46
 
33
47
  class Client
@@ -35,7 +49,6 @@ module Grammerb
35
49
 
36
50
  def initialize(api_id:, api_hash:, session: "grammerb.session", proxy: nil, logger: nil, pool_size: 20)
37
51
  @session_path = session
38
- @native = Grammerb::Native::Client.new(api_id, api_hash, session, proxy)
39
52
  @handlers = []
40
53
  @handlers_mu = Mutex.new
41
54
  @handlers_snapshot = [].freeze
@@ -47,6 +60,7 @@ module Grammerb
47
60
  @logger = logger || default_logger
48
61
  @entity_cache = {}
49
62
  @entity_cache_mu = Mutex.new
63
+ @native = Grammerb::Native::Client.new(api_id, api_hash, session, proxy)
50
64
  end
51
65
 
52
66
  # --- Connection ---
@@ -1,4 +1,4 @@
1
1
  # lib/grammerb/version.rb
2
2
  module Grammerb
3
- VERSION = "1.0.4"
3
+ VERSION = "1.0.5"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grammerb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Developer