Skip to content

Instantly share code, notes, and snippets.

@gfx
Created May 19, 2011 14:24
Show Gist options
  • Save gfx/980853 to your computer and use it in GitHub Desktop.
Save gfx/980853 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 $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