Skip to content

Instantly share code, notes, and snippets.

@adam12
Last active May 30, 2023 15:00
Show Gist options
  • Save adam12/793d9ea97815cdda37bdfad64202dda0 to your computer and use it in GitHub Desktop.
Save adam12/793d9ea97815cdda37bdfad64202dda0 to your computer and use it in GitHub Desktop.
require "async"
require "async/barrier"
Async do |task|
barrier = Async::Barrier.new
barrier.async do
puts "Inside task 1"
sleep 20
puts "Task 1 done"
end
barrier.async do
puts "Inside task 2"
sleep 10
puts "Task 2 done"
end
barrier.async do
puts "Inside task 3"
sleep 2
puts "Task 3 done"
end
puts "Waiting"
barrier.wait
puts "Done"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment