async 1.30.3 → 1.31.0

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
  SHA256:
3
- metadata.gz: f7bcca0b0eba6eebe85dd32baa0ffd67059bcdb0623416b818182bf779e38809
4
- data.tar.gz: 061a086ae31c238f1d2c3d17598400f3efc01a500de746105255f7582b90251c
3
+ metadata.gz: f54f8b2dedcd29cf6a5d5c19b9b6ef11762cac77156439930b29d414e45bb6d4
4
+ data.tar.gz: c420baf542fe9992737ac9d8594cd3f88bb7764904113d801aa891ec328558ee
5
5
  SHA512:
6
- metadata.gz: 455f569e561177f4f2e11e5f5713c6e04c5b30b54b01e860bca5e84770095b7f80c0d05d6afa7865773fbfb58c4170103a905ce9c3517c08fb9eec32f5a191a9
7
- data.tar.gz: b142a77817fcf868fa68f117d68fe05cf3d0ce34329855a2ef19be198924604b366deaa0ac0ec7bcaa151eaf244bb1e521908515aca44b5be1d82f794288f313
6
+ metadata.gz: ff4f467f2d8f2bde924e29636d8d0689509acfd1d463825173d03aa75b4235847db43c7fc6a9d4a10e18a444d542332218e1f3a9a0bb471d1a918bb411dd7a73
7
+ data.tar.gz: 95affc48630a0b2e83457e58024dfa89c091060b1047151849e30bce3a493a5e5ffaa06e824086df347dfb862f66cf834a08f3609d4b718eb7e3c74157bc1ad9
@@ -40,6 +40,25 @@ module Async
40
40
  # The tasks waiting on this semaphore.
41
41
  attr :waiting
42
42
 
43
+ # Allow setting the limit. This is useful for cases where the semaphore is used to limit the number of concurrent tasks, but the number of tasks is not known in advance or needs to be modified.
44
+ #
45
+ # On increasing the limit, some tasks may be immediately resumed. On decreasing the limit, some tasks may execute until the count is < than the limit.
46
+ #
47
+ # @parameter limit [Integer] The new limit.
48
+ def limit= limit
49
+ difference = limit - @limit
50
+ @limit = limit
51
+
52
+ # We can't suspend
53
+ if difference > 0
54
+ difference.times do
55
+ break unless fiber = @waiting.shift
56
+
57
+ fiber.resume
58
+ end
59
+ end
60
+ end
61
+
43
62
  # Is the semaphore currently acquired?
44
63
  def empty?
45
64
  @count.zero?
data/lib/async/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Async
24
- VERSION = "1.30.3"
24
+ VERSION = "1.31.0"
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.30.3
4
+ version: 1.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-15 00:00:00.000000000 Z
11
+ date: 2023-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: console
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  requirements: []
183
- rubygems_version: 3.3.7
183
+ rubygems_version: 3.4.7
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: A concurrency framework for Ruby.