async-limiter 1.5.2 → 1.5.3
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 +4 -4
- data/lib/async/limiter/version.rb +1 -1
- data/lib/async/limiter/window.rb +15 -0
- 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: dc95096df427d6b99502f8eb6f17f3cc0ec70598e093fd1d8aae5db50324d668
|
4
|
+
data.tar.gz: 21dfb9413922d3b20f1ee3f4ac9dbfd1ecdc5c2e08d12e9760c4b347cd941c0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3c074890ffa3befca024121f8988222539991ed43a99b99ccdcf2855b7e8219151ed118a2d549b490ad4992a2801c2af7e8fb43f315978176e1dab8db9657ec
|
7
|
+
data.tar.gz: 44ddac8caf55fa453604e57565e66c8bccd708cd710c76f65ad13f2408daa5442e3596dde2cd45e7a5bd33ed90e034a226c30cc98f85f57196e34059f7db4a7a
|
data/lib/async/limiter/window.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "async/clock"
|
2
|
+
require "async/notification"
|
2
3
|
require "async/task"
|
3
4
|
require_relative "constants"
|
4
5
|
|
@@ -26,6 +27,8 @@ module Async
|
|
26
27
|
|
27
28
|
@waiting = queue
|
28
29
|
@scheduler = nil
|
30
|
+
@yield_wait = false
|
31
|
+
@yield_notification = Notification.new
|
29
32
|
|
30
33
|
@window_frame_start_time = NULL_TIME
|
31
34
|
@window_start_time = NULL_TIME
|
@@ -158,7 +161,14 @@ module Async
|
|
158
161
|
# slipping in operations before other waiting fibers get resumed.
|
159
162
|
if blocking? || @waiting.any?
|
160
163
|
@waiting.push(fiber, *queue_args) # queue_args used for custom queues
|
164
|
+
@yield_wait = true
|
161
165
|
schedule if schedule?
|
166
|
+
|
167
|
+
# Non-blocking signal, prevents race condition where scheduler would
|
168
|
+
# start resuming waiting fibers before below 'Task.yield' was reached.
|
169
|
+
@yield_notification.signal
|
170
|
+
@yield_wait = false # we're out of the woods
|
171
|
+
|
162
172
|
loop do
|
163
173
|
Task.yield # run this line at least once
|
164
174
|
break unless blocking?
|
@@ -186,6 +196,11 @@ module Async
|
|
186
196
|
while @waiting.any? && !limit_blocking?
|
187
197
|
delay = [next_acquire_time - Clock.now, 0].max
|
188
198
|
task.sleep(delay) if delay.positive?
|
199
|
+
|
200
|
+
# Waits for the task that started the scheduler to yield.
|
201
|
+
# See #wait for more details.
|
202
|
+
@yield_wait && @yield_notification&.wait
|
203
|
+
|
189
204
|
resume_waiting
|
190
205
|
end
|
191
206
|
ensure
|