IO::Lambda

Non-blocking I/O in lambda style
Download

IO::Lambda Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Dmitry Karasik
  • Publisher web site:
  • http://search.cpan.org/~karasik/Prima-1.26/pod/Prima/Widget.pod

IO::Lambda Tags


IO::Lambda Description

Non-blocking I/O in lambda style IO::Lambda is a Perl module with non-blocking I/O in lambda style.SYNOPSISThe code below executes parallel HTTP requests use strict; use IO::Lambda qw(:lambda); use IO::Socket::INET; # create a lambda object sub http { my ( $host, $url) = @_; my $socket = IO::Socket::INET-> new( PeerAddr => $host, PeerPort => 80 ); lambda { context $socket; write { print $socket "GET $url HTTP/1.0 "; my $buf = ''; read { return $buf unless sysread( $socket, $buf, 1024, length($buf)); again; }}} } # fire up a single lambda and wait until it completes print http( 'www.perl.com', '/')-> wait; # fire up a lambda that waits for two http requests in parallel lambda { context http( 'www.perl.com', '/'), http( 'www.google.com', '/'); tails { print @_; } }-> wait;Note: io and lambda are synonyms - I personally prefer lambda but some find the word slightly inappropriate, hence io.This module is another attempt to fight the horrors of non-blocking I/O programming. It tries to bring back the simplicity of the declarative programming style, that is only otherwise available when one employs threads, coroutines, or co-processes. Usually coding non-blocking I/O for single process, single thread programs requires construction of state machines, often fairly complex, which doesn't help the clarity of the code. Not unlike monads in functional languages, that enforce order of execution over generally orderless functions, this framework helps programmer to express the order of execution of I/O callbacks in a coding style that resembles sequential, declarative programming.The manual begins with code examples, then explains basic assumptions, then finally gets of the complex concepts, where the real fun begins. You may skip directly there ("Stream IO"), where functional style mixes with I/O. Requirements: · Perl


IO::Lambda Related Software