• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

eg/H18-Mar-2012-1,326985

lib/IO/H18-Mar-2012-8,8324,211

t/H18-Mar-2012-1,6091,225

ChangesH A D18-Mar-20123.7 KiB193131

MANIFESTH A D18-Mar-20121.5 KiB7473

META.jsonH A D18-Mar-20121.1 KiB4847

META.ymlH A D18-Mar-2012607 2928

Makefile.PLH A D14-Mar-20121.6 KiB6143

READMEH A D14-Mar-20121.5 KiB5345

README

1IO::Lambda - nonblocking IO in functional style
2===============================================
3
4This module is another attempt to fight the horrors of non-blocking I/O
5programming. The simplicity of the sequential programming is only available
6when one employs threads, coroutines, or coprocesses. Otherwise state machines
7are to be built, often quite complex, which fact doesn't help the clarity of
8the code. This module uses closures to achieve clarity of sequential
9programming with single-process, single-thread, non-blocking I/O.
10
11The approach implemented in this module is strongly based on closures.
12It emulates the blocking style, so the collection of states is local, and can
13be collected under single subroutine. For example, a dumbed down HTTP protocol
14can be described like in the following scheme:
15
16
17	writable {
18		print $fh "GET /\r\n\r\n" or die;
19		readable {
20			sysread $fh or die;
21			read_again;
22		}
23	}
24
25IO::Lambda features syntax where one can indeed use the lambda syntax.
26Below is a full-functioning code:
27
28	use strict;
29	use IO::Lambda qw(:lambda);
30	use IO::Socket::INET;
31	my $q = lambda {
32		my ( $socket, $url) = @_;
33		context $socket;
34		writable {
35			print $socket "GET $url HTTP/1.0\r\n\r\n";
36			my $buf = '';
37			readable {
38				return $buf unless
39					sysread( $socket, $buf, 1024, length($buf));
40				again;
41			}
42		}
43	};
44	print $q-> wait(
45		IO::Socket::INET-> new(
46			PeerAddr => 'www.perl.com',
47			PeerPort => 80
48		),
49		'/index.html'
50	);
51
52For more examples, see eg/ directory.
53