async-limiter 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/limiter/concurrent.rb +18 -6
- data/lib/async/limiter/unlimited.rb +12 -0
- data/lib/async/limiter/version.rb +1 -1
- data/lib/async/limiter/window.rb +10 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f0332a099a13957c6de625c09512af704eeaa2c513b5460bcf213315e21e120
|
4
|
+
data.tar.gz: 6c3b884613ff5128c7443bd376ba6885c6d6b408c2be8e5e87a669ae1b232f5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
34
|
-
|
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
|
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
|
data/lib/async/limiter/window.rb
CHANGED
@@ -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
|
60
|
-
|
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
|
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
|