async 1.29.0 → 1.30.1

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: 421b9e871d367ee3c769c4f7a9f3e51125d5e11c45d37f9d8c562a33ecce70ed
4
- data.tar.gz: 868be7ef14d83fb04620c862d69b38e03f0b5ba036cd2d65e6caf0f45c58a689
3
+ metadata.gz: f8503897fe2c8f3b9593655310b259ee33d2a3774e65d7882524289286cea163
4
+ data.tar.gz: 952c6d1fd722b83efb95ffc3e4153c87d5925359aa403235f63496f984699588
5
5
  SHA512:
6
- metadata.gz: 47620eaf32dc53e1978f3c07ef66823c6aa4b3e85ec23ac3a207d1cdb39a06c790428a9b67dc3b955b74edf723faa567b2f8a077893ecf0c3d1383c5c62997e0
7
- data.tar.gz: 74e3b0e17cc0d8f63bdc2c7e4aa40033062a07d2a5a1866f3ca3ac072376264463f8b11203485a07bbed11c475cbad6a2ac81f9297e900a732263f8b7b0b401b
6
+ metadata.gz: 7b6c1a440279e389c4750ac7b7b716d19f05e31b29c67e3b712692b54877dca265eff31994d9a9220a1be7fa44fc79622f244a188e470e46f4a52b343e8b7638
7
+ data.tar.gz: 1c33f438780355d349dbe78ea0706cfcdc4165f3f402aae26042414f01a975e20a1f244621ca1486c36d10877b7b4d825a4c0aed6ef6a3a69dc0a41c1cd38ace
data/lib/async/barrier.rb CHANGED
@@ -50,11 +50,26 @@ module Async
50
50
  @tasks.empty?
51
51
  end
52
52
 
53
- # Wait for tasks in FIFO order.
53
+ # Wait for all tasks.
54
+ # @asynchronous Will wait for tasks to finish executing.
54
55
  def wait
55
- while task = @tasks.shift
56
- task.wait
56
+ # TODO: This would be better with linked list.
57
+ while @tasks.any?
58
+ task = @tasks.first
59
+
60
+ begin
61
+ task.wait
62
+ ensure
63
+ # Remove the task from the waiting list if it's finished:
64
+ @tasks.shift if @tasks.first == task
65
+ end
57
66
  end
58
67
  end
68
+
69
+ def stop
70
+ # We have to be careful to avoid enumerating tasks while adding/removing to it:
71
+ tasks = @tasks.dup
72
+ tasks.each(&:stop)
73
+ end
59
74
  end
60
75
  end
data/lib/async/node.rb CHANGED
@@ -302,8 +302,31 @@ module Async
302
302
  end
303
303
  end
304
304
 
305
- def stop
306
- @children&.each(&:stop)
305
+ # Immediately terminate all children tasks, including transient tasks.
306
+ # Internally invokes `stop(false)` on all children.
307
+ def terminate
308
+ # Attempt to stop the current task immediately, and all children:
309
+ stop(false)
310
+
311
+ # If that doesn't work, take more serious action:
312
+ @children&.each do |child|
313
+ child.terminate
314
+ end
315
+ end
316
+
317
+ # Attempt to stop the current node immediately, including all non-transient children.
318
+ # Invokes {#stop_children} to stop all children.
319
+ # @parameter later [Boolean] Whether to defer stopping until some point in the future.
320
+ def stop(later = false)
321
+ # The implementation of this method may defer calling `stop_children`.
322
+ stop_children(later)
323
+ end
324
+
325
+ # Attempt to stop all non-transient children.
326
+ private def stop_children(later = false)
327
+ @children&.each do |child|
328
+ child.stop(later) unless child.transient?
329
+ end
307
330
  end
308
331
 
309
332
  def print_hierarchy(out = $stdout, backtrace: true)
data/lib/async/reactor.rb CHANGED
@@ -293,32 +293,23 @@ module Async
293
293
  Console.logger.debug(self) {"Exiting run-loop because #{$! ? $! : 'finished'}."}
294
294
  end
295
295
 
296
- def stop(later = true)
297
- @children&.each do |child|
298
- # We don't want this process to propagate `Async::Stop` exceptions, so we schedule tasks to stop later.
299
- child.stop(later)
300
- end
301
- end
302
-
303
296
  # Stop each of the children tasks and close the selector.
304
- #
305
- # @return [void]
306
297
  def close
307
- # This is a critical step. Because tasks could be stored as instance variables, and since the reactor is (probably) going out of scope, we need to ensure they are stopped. Otherwise, the tasks will belong to a reactor that will never run again and are not stopped.
308
- self.stop(false)
298
+ # This is a critical step. Because tasks could be stored as instance variables, and since the reactor is (probably) going out of scope, we need to ensure they are stopped. Otherwise, the tasks will belong to a reactor that will never run again and are not stopped:
299
+ self.terminate
309
300
 
310
301
  @selector.close
311
302
  @selector = nil
312
303
  end
313
304
 
314
305
  # Check if the selector has been closed.
315
- # @return [Boolean]
306
+ # @returns [Boolean]
316
307
  def closed?
317
308
  @selector.nil?
318
309
  end
319
310
 
320
311
  # Put the calling fiber to sleep for a given ammount of time.
321
- # @param duration [Numeric] The time in seconds, to sleep for.
312
+ # @parameter duration [Numeric] The time in seconds, to sleep for.
322
313
  def sleep(duration)
323
314
  fiber = Fiber.current
324
315
 
@@ -71,7 +71,7 @@ module Async
71
71
  rescue TimeoutError
72
72
  return nil
73
73
  ensure
74
- wrapper.reactor = nil
74
+ wrapper&.reactor = nil
75
75
  end
76
76
 
77
77
  # Wait for the specified process ID to exit.
data/lib/async/task.rb CHANGED
@@ -156,7 +156,6 @@ module Async
156
156
  # Soon to become attr :result
157
157
 
158
158
  # Stop the task and all of its children.
159
- # @return [void]
160
159
  def stop(later = false)
161
160
  if self.stopped?
162
161
  # If we already stopped this task... don't try to stop it again:
@@ -250,9 +249,7 @@ module Async
250
249
  # logger.debug(self) {"Task was stopped with #{@children&.size.inspect} children!"}
251
250
  @status = :stopped
252
251
 
253
- @children&.each do |child|
254
- child.stop(true)
255
- end
252
+ stop_children(true)
256
253
  end
257
254
 
258
255
  def make_fiber(&block)
data/lib/async/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Async
24
- VERSION = "1.29.0"
24
+ VERSION = "1.30.1"
25
25
  end
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.29.0
4
+ version: 1.30.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: 2021-04-10 00:00:00.000000000 Z
11
+ date: 2021-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: console
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  requirements: []
182
- rubygems_version: 3.2.3
182
+ rubygems_version: 3.0.3.1
183
183
  signing_key:
184
184
  specification_version: 4
185
185
  summary: A concurrency framework for Ruby.