Created
May 18, 2025 09:41
-
-
Save barodeur/4a32206a0136dc61437d336aa698e4c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
source 'https://rubygems.org' | |
ruby "3.4.4" | |
gem "async" |
This file contains hidden or 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
GEM | |
remote: https://rubygems.org/ | |
specs: | |
async (2.24.0) | |
console (~> 1.29) | |
fiber-annotation | |
io-event (~> 1.9) | |
metrics (~> 0.12) | |
traces (~> 0.15) | |
console (1.30.2) | |
fiber-annotation | |
fiber-local (~> 1.1) | |
json | |
fiber-annotation (0.2.0) | |
fiber-local (1.1.0) | |
fiber-storage | |
fiber-storage (1.0.1) | |
io-event (1.10.0) | |
json (2.12.0) | |
metrics (0.12.2) | |
traces (0.15.2) | |
PLATFORMS | |
arm64-darwin-24 | |
ruby | |
DEPENDENCIES | |
async | |
RUBY VERSION | |
ruby 3.4.4p34 | |
BUNDLED WITH | |
2.6.7 |
This file contains hidden or 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
require "bundler/setup" | |
require "async" | |
require "async/barrier" | |
require "async/waiter" | |
Async do | |
barrier = Async::Barrier.new | |
waiter = Async::Waiter.new(parent: barrier) | |
t1 = waiter.async do | |
2.times do | |
puts "t1" | |
sleep 1 | |
end | |
end | |
t2 = waiter.async do | |
loop do | |
puts "t2" | |
sleep 1 | |
end | |
end | |
begin | |
done = waiter.wait(1) | |
puts "done: #{done}" | |
rescue => err | |
pp err | |
ensure | |
barrier.stop | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment