vlad_s has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm writing a POE-based application that should do the following:
In other words I'd like to ensure that my generated events make their way into the event queue before the "next line available" event arrives from ReadWrite. This doesn't seem to be the case if I use post() or yield() for generated events.
One solution that seems possible would be using POE::Kernel::call() rather than post(). In that case the InputEvent handler won't return until all processing is done. However, for certain reasons this approach doesn't work for me and I'd like to use post().
To illustrate the isssue, here's a simple piece of code:
use POE qw(Wheel::ReadWrite); my $S2 = POE::Session->create( inline_states => { _start => sub { $_[HEAP]->{reader} = POE::Wheel::ReadWrite->new( Handle => \*STDIN, InputEvent => 'got_input', ); }, got_input => \&got_input, bang => \&bang, } ); sub got_input { print $_[ARG0], "\n"; $poe_kernel->yield('bang', $_[ARG0]); } sub bang { print "Bang\n"; } $poe_kernel->run();
If I feed a 5-line file to this script, the following gets printed:
This is line number 1 This is line number 2 This is line number 3 This is line number 4 This is line number 5 Bang Bang Bang Bang Bang
Whereas what I want is:
This is line number 1 Bang This is line number 2 Bang This is line number 3 Bang This is line number 4 Bang This is line number 5 Bang
Anybody aware of an easy way of doing it?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: POE::Wheel::ReadWrite: "low priority" events
by rcaputo (Chaplain) on Jan 20, 2012 at 17:33 UTC | |
by vlad_s (Novice) on Jan 20, 2012 at 18:11 UTC | |
by rcaputo (Chaplain) on Jun 24, 2012 at 22:14 UTC | |
by jdporter (Paladin) on Jun 24, 2012 at 22:32 UTC | |
|
Re: POE::Wheel::ReadWrite: "low priority" events
by rcaputo (Chaplain) on Jan 20, 2012 at 17:47 UTC | |
by vlad_s (Novice) on Jan 20, 2012 at 22:23 UTC | |
by vlad_s (Novice) on Jan 21, 2012 at 18:03 UTC |