use CPS qw( kpareach );This produces such output as:
use IO::Async::Loop;
my $loop = IO::Async::Loop->new;
kpareach( \@ARGV,
sub {
my ( $val, $k ) = @_;
$loop->enqueue_timer(
delay => $val,
code => sub { print "$val\n"; goto $k },
);
},
sub { $loop->loop_stop },
);
$loop->loop_forever;
$ perl sleepsort.pl 3 8 4 2 6 5 7 1It's a little more verbose than I'd like it though. I have been pondering creating a CPS::Async module, which would provide some more simple CPS-like versions of the usual blocking primatives we're used to, like sleep and sysread. Using this new hypothetical module would lead to something looking like:
1
2
3
4
5
6
7
8
use CPS qw( kpareach );This would be a small wrapper around IO::Async, providing CPS-style functions that turn into method calls on some implied IO::Async::Loop object; similar to for example, the AnyEvent::Impl::IOAsync, which exposes an AnyEvent API using IO::Async.
use CPS::Async qw( ksleep );
kpareach( \@ARGV,
sub {
my ( $val, $k ) = @_;
ksleep( $val, sub {
print "$val\n";
goto $k;
} );
},
sub { CPS::Async::stop },
);
CPS::Async::run;
I have plenty of other projects to keep me amused currently, but I'll sit it on the back burner in case something interesting happens that way...
No comments:
Post a Comment