#!/usr/bin/perl use strict; use warnings; use AnyEvent; while (1) { my $cv = AE::cv; my (@output, @input); my $input_waiting = AE::cv; my $output_waiting = AE::cv; my $input_from_stdin = AE::io *STDIN, 0, sub { my $input = ; # read it push(@input, $input); $input_waiting->send; }; # what to do when $input_waiting has sent $input_waiting->cb( sub { push(@output, 'done'); $output_waiting->send; }); # what to do when $output_waiting has sent $output_waiting->cb( sub { print shift(@output) ."\n"; $cv->send; }); # wait for the main condvar $cv->recv; }