Sha256: 093d116dbd41a17d8376dda5061f3d9a41da06152bddf494bb5b8a6b0f489a60
Contents?: true
Size: 1.01 KB
Versions: 5
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true require_relative 'group' require_relative 'thread' require_relative 'process' group = Async::Container::Group.new thread_monitor = Fiber.new do while true thread = Async::Container::Thread.fork do |instance| if rand < 0.2 raise "Random Failure!" end instance.send(ready: true, status: "Started Thread") sleep(1) end status = group.wait_for(thread) do |message| puts "Thread message: #{message}" end puts "Thread status: #{status}" end end.resume process_monitor = Fiber.new do while true # process = Async::Container::Process.fork do |instance| # if rand < 0.2 # raise "Random Failure!" # end # # instance.send(ready: true, status: "Started Process") # # sleep(1) # end process = Async::Container::Process.spawn('bash -c "sleep 1; echo foobar; sleep 1; exit -1"') status = group.wait_for(process) do |message| puts "Process message: #{message}" end puts "Process status: #{status}" end end.resume group.wait
Version data entries
5 entries across 5 versions & 1 rubygems