async-limiter 1.5.2 → 1.5.3

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: 180ea4ebb784a29df337fe94e8190358482658fd07547ccaeaddc0974b271696
4
- data.tar.gz: b02a1c5978f4b14e103852bbaa3685d8e1258b6d0190d1bb1e3c157a18b786e9
3
+ metadata.gz: dc95096df427d6b99502f8eb6f17f3cc0ec70598e093fd1d8aae5db50324d668
4
+ data.tar.gz: 21dfb9413922d3b20f1ee3f4ac9dbfd1ecdc5c2e08d12e9760c4b347cd941c0a
5
5
  SHA512:
6
- metadata.gz: e0cd30fb437861e2077f1d15bd39a2bd9314ac64a7d48d2d303302a2c13c875cae02f042ad0d93531bf125475b62c1cc1b2e532279b044623f0b7b8765732bbb
7
- data.tar.gz: abd67afa695c11d045f176cf5371046238050f951626cc5bc2f2b10a484ff567cd63e26ceb8b9896fb052b55682081d9bc421e9d6e489cdbc34c68fee38bc922
6
+ metadata.gz: b3c074890ffa3befca024121f8988222539991ed43a99b99ccdcf2855b7e8219151ed118a2d549b490ad4992a2801c2af7e8fb43f315978176e1dab8db9657ec
7
+ data.tar.gz: 44ddac8caf55fa453604e57565e66c8bccd708cd710c76f65ad13f2408daa5442e3596dde2cd45e7a5bd33ed90e034a226c30cc98f85f57196e34059f7db4a7a
@@ -1,5 +1,5 @@
1
1
  module Async
2
2
  module Limiter
3
- VERSION = "1.5.2"
3
+ VERSION = "1.5.3"
4
4
  end
5
5
  end
@@ -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
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.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Sutic