async 1.4.0 → 1.4.1

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: c4f42d14b27e2c7835cd745cae1e3fed8cea3ab36e4e919676b38673fc8adf32
4
- data.tar.gz: 8944fd0464f0f1ef8135440bf4caa5a0235a0ef03de5e115609794c2a880ef76
3
+ metadata.gz: 44eb7af07e00729f3e1ecc10e98cd7cda6d09a117a9d3f62e33a22d5fc7068b4
4
+ data.tar.gz: 115e88de10b11bb887b3a17c1c82f29d9ea1d082e13ac874e5311c37cfc7cdaf
5
5
  SHA512:
6
- metadata.gz: 3843d40191f22c646adfd596bb0360431dcca7152127fb90154932b430d2cbcee4e6a6479b804b34ebceef0b92535bf46d7c856a0c3aed6c3b9843c5973c2a09
7
- data.tar.gz: cc595c9163bf0819bdb5f2029685bc4839faa569f88cb6cb969662d89732f2a0c25da0f7b78f297eb061e4c54d68e50ae6a5ed079a13a781f846cfee47edcea6
6
+ metadata.gz: 7a48d12ecd04670b4d552772bf882c190230aa15cb1946f0558d46f3bf9b50d321d160128d2667db57b6531af26ca01a68457754c40b9aa91135bfb63d36e983
7
+ data.tar.gz: b56e6e3e0ccf58fd47f70f99209badf9c536430ffe3d8fac7f4f6694670c06d2e4861e61f87d4767822a01264b1b0ad5fede8ab23e8d35a9a4d5cdc8ba6cc537
@@ -131,6 +131,10 @@ module Async
131
131
  Fiber.yield
132
132
  end
133
133
 
134
+ def finished?
135
+ super && @ready.empty?
136
+ end
137
+
134
138
  # Run the reactor until either all tasks complete or {#stop} is invoked.
135
139
  # Proxies arguments to {#async} immediately before entering the loop.
136
140
  def run(*args, &block)
@@ -142,22 +146,33 @@ module Async
142
146
  initial_task = async(*args, &block) if block_given?
143
147
 
144
148
  @timers.wait do |interval|
149
+ if @ready.any?
150
+ @ready.each do |fiber|
151
+ fiber.resume if fiber.alive?
152
+ end
153
+
154
+ @ready.clear
155
+
156
+ # The above tasks may schedule, cancel or affect timers in some way. We need to compute a new wait interval for the blocking selector call below:
157
+ interval = @timers.wait_interval
158
+ end
159
+
145
160
  # - nil: no timers
146
161
  # - -ve: timers expired already
147
162
  # - 0: timers ready to fire
148
163
  # - +ve: timers waiting to fire
149
- interval = 0 if interval && interval < 0
164
+ if interval && interval < 0
165
+ interval = 0
166
+ end
150
167
 
151
168
  # Async.logger.debug{"[#{self} Pre] Updating #{@children.count} children..."}
152
169
  # As timeouts may have been updated, and caused fibers to complete, we should check this.
153
170
 
154
- @ready.each do |fiber|
155
- fiber.resume if fiber.alive?
156
- end; @ready.clear
157
-
158
171
  # If there is nothing to do, then finish:
159
172
  # Async.logger.debug{"[#{self}] @children.empty? = #{@children.empty?} && interval #{interval.inspect}"}
160
- return initial_task if @children.empty? && interval.nil?
173
+ if !interval && self.finished?
174
+ return initial_task
175
+ end
161
176
 
162
177
  # Async.logger.debug{"Selecting with #{@children.count} fibers interval = #{interval.inspect}..."}
163
178
  if monitors = @selector.select(interval)
@@ -171,7 +186,7 @@ module Async
171
186
 
172
187
  return initial_task
173
188
  ensure
174
- Async.logger.debug{"[#{self} Ensure] Exiting run-loop (stopped: #{@stopped} exception: #{$!.inspect})..."}
189
+ Async.logger.debug(self) {"Exiting run-loop because #{$! ? $!.inspect : 'finished'}."}
175
190
  @stopped = true
176
191
  end
177
192
 
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Async
22
- VERSION = "1.4.0"
22
+ VERSION = "1.4.1"
23
23
  end
@@ -7,7 +7,7 @@ RSpec.describe Async::Wrapper do
7
7
  let(:input) {described_class.new(pipe.first)}
8
8
  let(:output) {described_class.new(pipe.last)}
9
9
 
10
- it "should be fast to parse large documents" do
10
+ it "should be fast to wait until readable" do
11
11
  Benchmark.ips do |x|
12
12
  x.report('Wrapper#wait_readable') do |repeats|
13
13
  Async::Reactor.run do |task|
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.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-21 00:00:00.000000000 Z
11
+ date: 2018-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r