IO-Events

 view release on metacpan or  search on metacpan

Events.pm  view on Meta::CPAN

IO::Events - Non-blocking IO using events 

=head1 SYNOPSIS

Example 1, run 'bc' as a co-process:

	use IO::Events;

	my $loop = IO::Events::Loop-> new();

	my $stdin_alive = 1;
	my $calculator = IO::Events::Process::ReadWrite-> new(
		owner    => $loop,
		process  => 'bc -l', 
		on_read  => sub {
			while ( my $line = $_[0]-> readline) {
				print "bc says: $line";
			}
		},
		on_close => sub {
			exit 1 if $stdin_alive; # fork/exec error
		}
	);

	my $stdin = IO::Events::stdin-> new(
		owner => $loop,
		on_read => sub { 
		$calculator-> write( $_[0]-> read );
		},
		on_close => sub {
			$stdin_alive = 0;
			exit;
		},
	);

	$loop-> yield while 1;


Example 2, connect to/listen on a TCP port within a single process:

	use IO::Events;



( run in 0.624 second using v1.01-cache-2.11-cpan-39bf76dae61 )