Created
December 12, 2017 16:29
-
-
Save adis-io/dbfad7c83ae8e8a16019ba791e3899e5 to your computer and use it in GitHub Desktop.
github.com/forkbreak/fork_break - usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require 'bundler/inline' | |
rescue LoadError => e | |
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' | |
raise e | |
end | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'fork_break' | |
end | |
process1, process2, process3 = Array.new(3) do |i| | |
ForkBreak::Process.new do |breakpoints| | |
random = Random.rand(1.0) | |
puts "sleep for #{random}" | |
sleep(random) | |
breakpoints << :after_sleep_1 | |
puts "Process: #{i}" | |
puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') | |
sleep(2) | |
breakpoints << :after_sleep_2 | |
end | |
end | |
process1.run_until(:after_sleep_1).wait | |
process2.run_until(:after_sleep_1).wait | |
process3.run_until(:after_sleep_1).wait | |
process1.finish | |
process2.finish | |
process3.finish.wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Approx. output: