Created
May 19, 2011 14:24
-
-
Save gfx/980853 to your computer and use it in GitHub Desktop.
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
#!perl -w | |
use common::sense; | |
use AnyEvent; | |
use Data::Dumper; | |
sub sleep_sort { | |
my @args = @_; | |
my $cv = AnyEvent->condvar; | |
my @output; | |
foreach my $value(@args) { | |
my $w; | |
$w = AnyEvent->timer( | |
after => $value / 10, | |
cb => sub { | |
push @output, $value; | |
undef $w; | |
$cv->send(); | |
}, | |
); | |
} | |
$cv->recv() for @args; | |
return @output; | |
} | |
print Dumper([ sleep_sort @ARGV ]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment