Skip to content

Instantly share code, notes, and snippets.

@uu59
Created May 20, 2011 02:07
Show Gist options
  • Save uu59/982218 to your computer and use it in GitHub Desktop.
Save uu59/982218 to your computer and use it in GitHub Desktop.
sleep sort examples inspired by http://dis.4chan.org/read/prog/1295544154
# -- coding: utf-8
require "rubygems"
require "cool.io"
class SleepSort < Coolio::TimerWatcher
def initialize(num)
super(*num.to_f)
@num = num
end
def on_timer
puts @num
detach
end
end
coolio = Coolio::Loop.default
ARGV.each{|n|
coolio.attach SleepSort.new(n)
}
coolio.run
# -- coding: utf-8
require "rubygems"
require "eventmachine"
EM.run do
counter = ARGV.length
ARGV.each{|n|
EM.add_timer(n.to_f) do
puts n
EM.stop if (counter -= 1) == 0
end
}
end
# -- coding: utf-8
require "thread"
ARGV.map{|n|
Thread.start(n) do
sleep n.to_f
puts n
end
}.each(&:join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment