Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created October 20, 2012 22:55
Show Gist options
  • Save havenwood/3925123 to your computer and use it in GitHub Desktop.
Save havenwood/3925123 to your computer and use it in GitHub Desktop.
Sleepy FizzBuzz
require 'celluloid'
class SleepyFizzBuzz
include Celluloid
def buzz n
sleep 0.1 # making the FizzBuzz sleepy!
if n % 15 == 0
puts 'FizzBuzz'
elsif n % 3 == 0
puts 'Fizz'
elsif n % 5 == 0
puts 'Buzz'
else
puts n
end
end
end
fizz = SleepyFizzBuzz.new
1.upto(100) { |n| fizz.async.buzz n } # fast
1.upto(100) { |n| fizz.buzz n } # slow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment