Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created November 16, 2019 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/119e16d7728cb00306739137b30d75a9 to your computer and use it in GitHub Desktop.
Save havenwood/119e16d7728cb00306739137b30d75a9 to your computer and use it in GitHub Desktop.
Example Async equivalent to code naftilos76's code that phaul is helping with on #ruby IRC: https://gist.github.com/phaul/2b2166c913452f010b1513a8165ab287
require 'async'
condition = Async::Condition.new
Async do
task_one = Async do
loop do
puts 'task one before waiting'
condition.wait
end
end
Async do
puts 'task two signalling'
condition.signal
puts 'still task two'
task_one.stop
end
end
#>> task one before waiting
#>> task two signalling
#>> task one before waiting
#>> still task two
#=> #<Async::Task:0xcefacedfe (complete)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment