Skip to content

Instantly share code, notes, and snippets.

@rlogwood
Created March 2, 2022 23:07
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 rlogwood/bc0d10a2a7c461f25bba5ec05372d622 to your computer and use it in GitHub Desktop.
Save rlogwood/bc0d10a2a7c461f25bba5ec05372d622 to your computer and use it in GitHub Desktop.
Simple demonstration of ruby fiber scheduler
# quick demo of fiber scheduling
# Ruby 3.1.1
# see https://brunosutic.com/blog/ruby-fiber-scheduler
# see https://rubyapi.org/3.0/o/fiber/schedulerinterface
# see https://github.com/bruno-/fiber_scheduler_list
# using a default implementation of fiber_scheduler via
# gem install fiber_scheduler
require 'fiber_scheduler'
started_at = Time.now
Fiber.set_scheduler(FiberScheduler.new)
10_000.times do
Fiber.schedule do
sleep 2
end
end
puts "Time to finish scheduling: #{(Time.now - started_at)}"
at_exit do
puts "Total Duration for 10,000 sleeps of 2 seconds: #{(Time.now - started_at)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment