Skip to content

Instantly share code, notes, and snippets.

@punytan
Forked from gfx/ae-sleep-sort.pl
Created May 19, 2011 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save punytan/980866 to your computer and use it in GitHub Desktop.
Save punytan/980866 to your computer and use it in GitHub Desktop.
#!perl -w
use common::sense;
use AnyEvent;
use Data::Dumper;
sub sleep_sort {
my @args = @_;
my @output;
my $cv = AnyEvent->condvar;
for my $value (@args) {
$cv->begin;
my $w; $w = AE::timer $value, 0, sub {
push @output, $value;
undef $w;
$cv->end;
}
}
$cv->recv;
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