Created
May 19, 2011 15:04
-
-
Save xaicron/980963 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
use strict; | |
use warnings; | |
use AE; | |
use List::Util qw(max); | |
use Data::Dumper; | |
sub sleep_sort { | |
my @args = @_; | |
my (@w, @rv); | |
my $cv = AE::cv; | |
my $wait = 0; | |
for my $argv (@args) { | |
push @w, AE::timer $argv, 0, sub { push @rv, $argv }; | |
$wait = max($wait, $argv); | |
} | |
my $sender = AE::timer $wait + 0.1, 0, sub { $cv->send(@rv) }; | |
return $cv->recv; | |
} | |
print Dumper [ sleep_sort 2, 4, 1, 3 ]; | |
print Dumper [ sleep_sort 2.4, 0.5, 1.111, 3.14 ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment