http://www.perlmonks.org?node_id=736424


in reply to Re^3: regarding 1.02 (was Re: IO::Lambda: call for participation)
in thread IO::Lambda: call for participation

So these are really "on_next_writable" and "on_next_readable" rather than general event handlers. (Unless they are reset with again().) That's definitely different from POE, in which event handlers persist once set.

So, conceptually, it's sort of like this (in a sort of pseudo-code and with some lexical scope differences so that the function references are explicit which I think makes the order of execution clearer):

my ($req, $socket, $buf); sub talk { $req = shift; $socket = IO::Socket::INET-> new( PeerAddr => 'www.perl.com', PeerPo +rt => 80); return lambda \&init; } sub init { when_writeable( $socket, \&write_handler ); } sub write_handler { send_request( $req => $socket ); when_readable( $socket, \&read_handler ); } sub read_handler { read_stuff( $socket => $buf ) or die; if ( done() ) { return $buf; } else { when_readable( $socket, \&read_handler ); } } my $q = talk( HTTP::Request-> new( GET => 'http://www.perl.com') ); print $q->wait;

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^5: regarding 1.02 (was Re: IO::Lambda: call for participation)
by dk (Chaplain) on Jan 15, 2009 at 00:44 UTC
    That's definitely different from POE, in which event handlers persist once set.

    Quite correct. I didn't realize that this is a key point difference until you've noticed it - thank you! I agree, it surely is. I should emphasize that in the docs.

    And yes, the code does the right flow.