Created
May 20, 2011 02:07
-
-
Save uu59/982218 to your computer and use it in GitHub Desktop.
sleep sort examples inspired by http://dis.4chan.org/read/prog/1295544154
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 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