Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: regarding 1.02 (was Re: IO::Lambda: call for participation)

by dk (Chaplain)
on Jan 14, 2009 at 23:54 UTC ( #736420=note: print w/ replies, xml ) Need Help??


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

The minor thing I decided not to correct, but just changed that decision: it's not quite

This sets up one of many parallel closures that process in parallel.

but rather

This sets up a new lambda object with attached one of many closures that process sequentially.

Per one lambda, only one writable will ever be executed; after it in turn registers readable, socket won't be listened for on_write events. Same is valid for readable.


Comment on Re^3: regarding 1.02 (was Re: IO::Lambda: call for participation)
Re^4: regarding 1.02 (was Re: IO::Lambda: call for participation)
by xdg (Monsignor) on Jan 15, 2009 at 00:21 UTC

    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.

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://736420]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-09-21 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls