async 1.29.0 → 1.30.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 +4 -4
 - data/lib/async/barrier.rb +18 -3
 - data/lib/async/node.rb +25 -2
 - data/lib/async/reactor.rb +4 -13
 - data/lib/async/scheduler.rb +1 -1
 - data/lib/async/task.rb +1 -4
 - data/lib/async/version.rb +1 -1
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f8503897fe2c8f3b9593655310b259ee33d2a3774e65d7882524289286cea163
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 952c6d1fd722b83efb95ffc3e4153c87d5925359aa403235f63496f984699588
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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 
     | 
| 
      
 53 
     | 
    
         
            +
            		# Wait for all tasks.
         
     | 
| 
      
 54 
     | 
    
         
            +
            		# @asynchronous Will wait for tasks to finish executing.
         
     | 
| 
       54 
55 
     | 
    
         
             
            		def wait
         
     | 
| 
       55 
     | 
    
         
            -
            			 
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
            		 
     | 
| 
       306 
     | 
    
         
            -
             
     | 
| 
      
 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. 
     | 
| 
      
 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 
     | 
    
         
            -
            		# @ 
     | 
| 
      
 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 
     | 
    
         
            -
            		# @ 
     | 
| 
      
 312 
     | 
    
         
            +
            		# @parameter duration [Numeric] The time in seconds, to sleep for.
         
     | 
| 
       322 
313 
     | 
    
         
             
            		def sleep(duration)
         
     | 
| 
       323 
314 
     | 
    
         
             
            			fiber = Fiber.current
         
     | 
| 
       324 
315 
     | 
    
         | 
    
        data/lib/async/scheduler.rb
    CHANGED
    
    
    
        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 
     | 
    
         
            -
            			 
     | 
| 
       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
    
    
    
        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 
     | 
    
         
            +
              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- 
     | 
| 
      
 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. 
     | 
| 
      
 182 
     | 
    
         
            +
            rubygems_version: 3.0.3.1
         
     | 
| 
       183 
183 
     | 
    
         
             
            signing_key:
         
     | 
| 
       184 
184 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       185 
185 
     | 
    
         
             
            summary: A concurrency framework for Ruby.
         
     |