async-limiter 1.2.0 → 1.3.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
  SHA256:
3
- metadata.gz: 974ccf48a69e44da7a7ae3d5908d68376ba026cfe8f72430aeda1fdb8b95966e
4
- data.tar.gz: bf910237393a4fcd04e91fa1160d1d4d44993f5de73bc1c8e86b31ba6c98db7b
3
+ metadata.gz: 0f0332a099a13957c6de625c09512af704eeaa2c513b5460bcf213315e21e120
4
+ data.tar.gz: 6c3b884613ff5128c7443bd376ba6885c6d6b408c2be8e5e87a669ae1b232f5e
5
5
  SHA512:
6
- metadata.gz: e1bf656e0d8f82bf460f64d657ad17ab9fedda4f06b335036448312e81c30e3cb9c438642aef86a704c25401563361a39f5b7258eb8ec7123bc10f719459db90
7
- data.tar.gz: a367575c970cf6e40723f53bbc776cf70fe88488d36dddb755b21c625dcc133ad84c812fbc8aa54ee0cdc202ddc50f96cc76a75c8e78f4ad18017459f2b5ed4a
6
+ metadata.gz: 87d13bfea8dabd356cf7662dc79011c0e78584fb5f0e917a79669fecc1c1c23851978508eb431cf7dcac55edcabcfc781ddefbc3cc2ea85cf37b0edeffa23757
7
+ data.tar.gz: 50789debe4ebef773acbacf47c76ae799ac418fe0ea69695a250fed60027fdc119c0c6c895b205a70edb3c950571a9fc07ea11ba1a0691f50b62f6141d6bd5cb
@@ -21,8 +21,8 @@ module Async
21
21
  limit_blocking?
22
22
  end
23
23
 
24
- def async(parent: (@parent || Task.current), **options)
25
- acquire
24
+ def async(*queue_args, parent: (@parent || Task.current), **options)
25
+ acquire(*queue_args)
26
26
  parent.async(**options) do |task|
27
27
  yield task
28
28
  ensure
@@ -30,9 +30,21 @@ module Async
30
30
  end
31
31
  end
32
32
 
33
- def acquire
34
- wait
33
+ def sync(*queue_args, &block)
34
+ acquire(*queue_args, &block)
35
+ end
36
+
37
+ def acquire(*queue_args)
38
+ wait(*queue_args)
35
39
  @count += 1
40
+
41
+ return unless block_given?
42
+
43
+ begin
44
+ yield
45
+ ensure
46
+ release
47
+ end
36
48
  end
37
49
 
38
50
  def release
@@ -53,11 +65,11 @@ module Async
53
65
  @count >= @limit
54
66
  end
55
67
 
56
- def wait
68
+ def wait(*queue_args)
57
69
  fiber = Fiber.current
58
70
 
59
71
  if blocking?
60
- @waiting << fiber
72
+ @waiting.push(fiber, *queue_args) # queue_args used for custom queues
61
73
  Task.yield while blocking?
62
74
  end
63
75
  rescue Exception # rubocop:disable Lint/RescueException
@@ -27,8 +27,20 @@ module Async
27
27
  end
28
28
  end
29
29
 
30
+ def sync(*queue_args, &block)
31
+ acquire(*queue_args, &block)
32
+ end
33
+
30
34
  def acquire
31
35
  @count += 1
36
+
37
+ return unless block_given?
38
+
39
+ begin
40
+ yield
41
+ ensure
42
+ release
43
+ end
32
44
  end
33
45
 
34
46
  def release
@@ -1,5 +1,5 @@
1
1
  module Async
2
2
  module Limiter
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -47,8 +47,8 @@ module Async
47
47
  limit_blocking? || window_blocking? || window_frame_blocking?
48
48
  end
49
49
 
50
- def async(parent: (@parent || Task.current), **options)
51
- acquire
50
+ def async(*queue_args, parent: (@parent || Task.current), **options)
51
+ acquire(*queue_args)
52
52
  parent.async(**options) do |task|
53
53
  yield task
54
54
  ensure
@@ -56,8 +56,12 @@ module Async
56
56
  end
57
57
  end
58
58
 
59
- def acquire
60
- wait
59
+ def sync(*queue_args, &block)
60
+ acquire(*queue_args, &block)
61
+ end
62
+
63
+ def acquire(*queue_args)
64
+ wait(*queue_args)
61
65
  @count += 1
62
66
 
63
67
  current_time = Clock.now
@@ -145,13 +149,13 @@ module Async
145
149
  @window_frame_start_time + window_frame <= Clock.now
146
150
  end
147
151
 
148
- def wait
152
+ def wait(*queue_args)
149
153
  fiber = Fiber.current
150
154
 
151
155
  # @waiting.any? check prevents fibers resumed via scheduler from
152
156
  # slipping in operations before other waiting fibers get resumed.
153
157
  if blocking? || @waiting.any?
154
- @waiting << fiber
158
+ @waiting.push(fiber, *queue_args) # queue_args used for custom queues
155
159
  schedule if schedule?
156
160
  loop do
157
161
  Task.yield # run this line at least once
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-limiter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Sutic