async 1.19.0 → 1.20.0

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: 0bbe9b738c758dc531ae3a13f10a4a5bdcfdadaf29e3dc51bc11e2daca28781d
4
- data.tar.gz: 31872ca49209a1038eb02ec0497bf968c68c84122c81f3bafd3b87773c653f1d
3
+ metadata.gz: db5bf4667851a5b5c7f18895a970d61429aaa4a3d09b67f1b27114f60c1b3be0
4
+ data.tar.gz: 5e01edfda229d537e214c5addc67460d533eb2096580f2055642f160c2f4c116
5
5
  SHA512:
6
- metadata.gz: 2caef4acc794a33d79a7f74a7bf98642d5b882e406a31cca62a7714fa4933123ff9565c769fe2aaf88e71f1ae34499cff847402fa07194c85dd70f61fa19b594
7
- data.tar.gz: 93a95a79cd6db4646108863121b60406f82e2ab4142ebba4108ac0cc7b23eec271d5a1cf4f1c9c7d3939ae17e3aba402f6f729a7bc3d56770fae49dac430ebe3
6
+ metadata.gz: 3353bb22a9f9669db6e417d575c953bb7c4384109459b437de5539c6ff0869957f02720bfbb878a6682678015a7d54ea7e67e2caf4c805d59c5fb57e470185be
7
+ data.tar.gz: bb6f76024fc98843c9ed1d08e834b9bfa0230deca26f4aa07b87eb8faf761922bab6a89f080b5dbae77b389b45ec8929bbcc0695cd4515058752b4250bd9b76c
data/lib/async/task.rb CHANGED
@@ -134,13 +134,20 @@ module Async
134
134
  # Stop the task and all of its children.
135
135
  # @return [void]
136
136
  def stop
137
- @children&.each(&:stop)
138
-
139
- if self.current?
140
- raise Stop, "Stopping current fiber!"
141
- elsif @fiber.alive?
142
- @fiber.resume(Stop.new)
137
+ if self.stopping?
138
+ # If we are already stopping this task... don't try to stop it again.
139
+ return true
140
+ elsif self.running?
141
+ @status = :stopping
142
+
143
+ if self.current?
144
+ raise Stop, "Stopping current fiber!"
145
+ elsif @fiber.alive?
146
+ @fiber.resume(Stop.new)
147
+ end
143
148
  end
149
+ ensure
150
+ @children&.each(&:stop)
144
151
  end
145
152
 
146
153
  # Lookup the {Task} for the current fiber. Raise `RuntimeError` if none is available.
@@ -176,10 +183,18 @@ module Async
176
183
  @status == :failed
177
184
  end
178
185
 
186
+ def stopping?
187
+ @status == :stopping
188
+ end
189
+
179
190
  def stopped?
180
191
  @status == :stopped
181
192
  end
182
193
 
194
+ def complete?
195
+ @status == :complete
196
+ end
197
+
183
198
  private
184
199
 
185
200
  # This is a very tricky aspect of tasks to get right. I've modelled it after `Thread` but it's slightly different in that the exception can propagate back up through the reactor. If the user writes code which raises an exception, that exception should always be visible, i.e. cause a failure. If it's not visible, such code fails silently and can be very difficult to debug.
data/lib/async/version.rb CHANGED
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Async
22
- VERSION = "1.19.0"
22
+ VERSION = "1.20.0"
23
23
  end
@@ -148,6 +148,26 @@ RSpec.describe Async::Task do
148
148
  expect(task).to be_stopped
149
149
  end
150
150
 
151
+ it "can stop nested tasks with exception handling" do
152
+ task = reactor.async do |task|
153
+ child = task.async do |subtask|
154
+ subtask.sleep(1)
155
+ end
156
+
157
+ begin
158
+ child.wait
159
+ ensure
160
+ child.stop
161
+ end
162
+ end
163
+
164
+ subtask = task.children.first
165
+ task.stop
166
+
167
+ expect(task.status).to be :stopped
168
+ expect(subtask.status).to be :stopped
169
+ end
170
+
151
171
  it "can stop current task" do
152
172
  state = nil
153
173
 
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.19.0
4
+ version: 1.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-17 00:00:00.000000000 Z
11
+ date: 2019-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r