This is a Fiber Schduler, which is a missing piece to do concurrent programming in Ruby language.
If you are not familiar with the concept of Fiber Schduler, please refer to my presentation: Ruby の FiberScheduler を布教したい. (Sorry in Japanese.)
Add this line to your application's Gemfile:
gem 'async_scheduler'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install async_scheduler
Set this scheduler in the current thread.
Then, surround each of blocking oerations in Fiber.schedule
block so that they are executed concurrently.
Fiber.set_schduler AsyncScheduler::Scheduler.new
Fiber.schedule do
File.read("file1.txt") # some blocking operation
end
Fiber.schedule do
File.read("file2.txt") # some blocking operation
end
puts "Finished"
Add and run spec.
bundle exec rspec
Bug reports and pull requests are welcome on GitHub at https://github.com/kudojp/async_scheduler. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the AsyncScheduler project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.