lib/async/container/hybrid.rb in async-container-0.16.4 vs lib/async/container/hybrid.rb in async-container-0.16.5

- old
+ new

@@ -31,15 +31,24 @@ count ||= processor_count ** 2 forks ||= [processor_count, count].min threads = (count / forks).ceil forks.times do - self.spawn(**options) do - container = Threaded::Container.new + self.spawn(**options) do |instance| + container = Threaded.new container.run(count: threads, **options, &block) + container.wait_until_ready + instance.ready! + container.wait + rescue Async::Container::Terminate + # Stop it immediately: + container.stop(false) + ensure + # Stop it gracefully (also code path for Interrupt): + container.stop end end return self end