Implements the async/await pattern for Ruby using async.
bundle add async-await
In any asynchronous context (e.g. a reactor), simply use the await
function like so:
require 'async/await'
class Coop
include Async::Await
async def count_chickens(area_name)
3.times do |i|
sleep rand
puts "Found a chicken in the #{area_name}!"
end
end
async def count_all_chickens
# These methods all run at the same time.
count_chickens("garden")
count_chickens("house")
# We wait for the result
count_chickens("tree").wait
end
end
coop = Coop.new
coop.count_all_chickens
We welcome contributions to this project.
- Fork it.
- Create your feature branch (
git checkout -b my-new-feature
). - Commit your changes (
git commit -am 'Add some feature'
). - Push to the branch (
git push origin my-new-feature
). - Create new Pull Request.
This project uses the Developer Certificate of Origin. All contributors to this project must agree to this document to have their contributions accepted.
This project is governed by the Contributor Covenant. All contributors and participants agree to abide by its terms.