class Async::Scheduler
def run_loop(initial = nil, &block)
@yields {...} The block to execute on each loop iteration.
@parameter initial [Proc | Nil] The initial block to execute before the first loop iteration.
Run the event loop, until the scheduler is interrupted or finished.
def run_loop(initial = nil, &block) pt = nil heory, we could use Exception here to be a little bit safer, but we've only shown the case for SignalException to be a problem, so let's not over-engineer this. .handle_interrupt(::SignalException => :never) do itial n tial.call re tial = nil self.interrupted? we are finished, we need to exit: k unless yield Interrupt => interrupt n interrupt did occur during an iteration of the event loop, we need to handle it. More specifically, `self.stop` is not safe to interrupt without potentially corrupting the task tree. .handle_interrupt(::SignalException => :never) do le.debug(self) do |buffer| er.puts "Scheduler interrupted: #{interrupt.inspect}" .print_hierarchy(buffer) stop e event loop was interrupted, and we finished exiting normally (due to the interrupt), we need to re-raise the interrupt so that the caller can handle it too. rrupt .raise(interrupt)