in reply to Re: POE::Wheel::ReadWrite: "low priority" events
in thread POE::Wheel::ReadWrite: "low priority" events

Thank you very much Rocco, the idea is clear.

However this assumes that we know which event is issued last - because that event must issue 'process_next_input'.

What if we don't know that - the number and order of events that get generated in the course of processing of a line is more or less random?

I changed your sample so that event step_two sometimes gets issued and sometimes doesn't. Also I added checking get_event_count() to see if there are any further events in the queue. Seems that achieved my goal:

sub do_step_one { print " step one: $_[ARG0]\n"; $_[KERNEL]->yield('step_two', $_[ARG0]) if rand(1) > 0.5; $_[KERNEL]->yield('process_next_input') if $poe_kernel->get_event_co +unt() == 0; } sub do_step_two { print " step two: $_[ARG0]\n"; $_[KERNEL]->yield('process_next_input') if $poe_kernel->get_event_co +unt() == 0; }

Thanks once again for your time!

Replies are listed 'Best First'.
Re^3: POE::Wheel::ReadWrite: "low priority" events
by rcaputo (Chaplain) on Jun 24, 2012 at 22:14 UTC

    You could implement the Chain of Responsibility design pattern by promoting ARG0 from an input string to a data structure that includes the input and the steps to process it.

    First define a subroutine to pass the job to the next step in the recipe:

    sub what_next { my ($kernel, $job) = @_; my $next_step = shift @{ $job->{recipe} }; if (defined $next_step) { $kernel->yield( $next_step => $job ); } else { $kernel->yield( 'process_next_input' ); } }

    process_next_input() builds the job and the initial recipe, and then uses what_next() to start the process:

    sub process_next_input { ...; my $job = { input => $next_input, recipe => [ 'step_one', 'step_two' ], }; what_next($_[KERNEL], $job); }

    All stages of the process end by calling what_next() to pass the work on. You could get fancy by pushing coderefs onto the recipe that conditionally return the next event in the chain.

    Sorry for not responding in so long. I'm doing PerlMonks wrong, and I don't notice my message inbox until I actively return to the site. If there's some sort of RSS-like way to check for messages, that would help a lot.

      I don't notice my message inbox until I actively return to the site.

      That's the way PerlMonks works; you're not doing it wrong. Unfortunately we don't (yet) have any other way of notifying users of events of interest, e.g. via email.

      If there's some sort of RSS-like way to check for messages, that would help a lot.

      Or that. :-)

      I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.