lib/async/scheduler.rb in async-2.4.0 vs lib/async/scheduler.rb in async-2.4.1

- old
+ new

@@ -48,13 +48,16 @@ Kernel::raise "Closing scheduler with blocked operations!" if @blocked > 0 # We depend on GVL for consistency: # @guard.synchronize do - @selector&.close + # We want `@selector = nil` to be a visible side effect from this point forward, specifically in `#interrupt` and `#unblock`. If the selector is closed, then we don't want to push any fibers to it. + selector = @selector @selector = nil + selector&.close + # end consume end @@ -67,13 +70,14 @@ def to_s "\#<#{self.description} #{@children&.size || 0} children (#{stopped? ? 'stopped' : 'running'})>" end # Interrupt the event loop and cause it to exit. + # @asynchronous May be called from any thread. def interrupt @interrupted = true - @selector.wakeup + @selector&.wakeup end # Transfer from the calling fiber to the event loop. def transfer @selector.transfer @@ -125,11 +129,13 @@ # @asynchronous May be called from any thread. def unblock(blocker, fiber) # $stderr.puts "unblock(#{blocker}, #{fiber})" # This operation is protected by the GVL: - @selector.push(fiber) - @selector.wakeup + if selector = @selector + selector.push(fiber) + selector.wakeup + end end # @asynchronous May be non-blocking.. def kernel_sleep(duration = nil) if duration