blob: 4dffb838661f295c5be33bbeeb658b2a027df89b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#!/Users/colincrain/perl5/perlbrew/perls/perl-5.32.0/bin/perl
#
# sort-yourself-sleepy.pl
#
#
#
# © 2021 colin crain
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
use warnings;
use strict;
use utf8;
use feature ":5.26";
use feature qw(signatures);
no warnings 'experimental::signatures';
use Coro;
use Coro::Timer;
my @arr = @ARGV;
scalar @arr == 0 and @arr = (3,2,1,5);
$|=1;
my $idx;
our @out;
sleep_chamber( @arr );
say "@out";
say sleep_chamber( @arr );
sub sleep_chamber ( @arr ) {
for $idx ( 0..$#arr ) {
async {
my $i = $idx;
say "processing $idx";
Coro::Timer::sleep($arr[$idx]);
push @out, $arr[$idx];
if ($i == $#arr) {
say "@out";
exit 1;
}
};
}
AnyEvent->condvar->recv;
}
|