This is a fiber scheduler for Ruby 3.0+ that uses EventMachine, allowing integration with projects that already use EventMachine.
If you are starting a new project and have no EventMachine-based dependencies, consider fiber_scheduler instead.
NOTE: fiber schedulers are per-thread settings. This scheduler may only be used on the EventMachine reactor thread.
require "em_fiberscheduler" require "em-http" require "open-uri" Fiber.set_scheduler(EM::FiberScheduler.new) Fiber.schedule do URI.open("https://httpbin.org/delay/2") end EM.schedule do EM::HttpRequest.new("https://httpbin.org/delay/2").get end
EM::FiberScheduler will start the EventMachine reactor for you, and also stop it when all work is complete. If any connection or server is still open, that will be considered work that is not yet complete. If you want to disable the autostart do this:
If you want to start EventMachine yourself but want the autostop behaviour, do this:
Fiber.set_scheduler(EM::FiberScheduler.new(autostart: false)) Fiber.scheduler.autostop
If you have any questions about this library, or wish to report a bug, please send email to: firstname.lastname@example.org
If you have code or patches you wish to contribute, the maintainer's preferred mechanism is a git pull request. Push your changes to a git repository somewhere, for example:
git remote rename origin upstream git remote add origin email@example.com:~yourname/em_fiberscheduler git push -u origin master
Then generate the pull request:
git fetch upstream master git request-pull -p upstream/master origin
And copy-paste the result into a plain-text email to: firstname.lastname@example.org
You may alternately use a patch-based approach as described on https://git-send-email.io or using the Sourcehut web interface.
Contributions follow an inbound=outbound model -- you (or your employer) keep all copyright on your patches, but agree to license them according to this project's COPYING file.