I once wrote a POE::API module that had a do_events_until and wait_until
methods that would let the kernel do other things until a variable was set
or a time passed - they both used run_one_timeslice but I found that that
method didnt have the granularity that my methods needed. ie. they would
run multiple events rather than just one or a few
On 3/8/07, Sun Yi-Ming <[EMAIL PROTECTED]> wrote:
Hi POE,
I formerly write a lot of event_driven code, and always involv
using a pattern like
while (not $done) {
do_sth_normally();
loop_once();
},
I also see about the run_one_timeslice method in Kernel, and I
always invented a little toy as workhorse to do that normally work:
package POE::Component::Normal::Workhorse;
use POE;
sub spawn {
$mi = shift;
my %params = @_;
my $done = delete $params{check_end};
my $work = delete $params{work};
my $context = delete $params{context};
POE::Session->create
( inline_states => {
_start => sub { $_[KERNEL]->yield( workhorse ) },
workhorse => sub {
return if $done->();
$_[KERNEL]->yield( workhorse );
$work->($_[HEAP]->{context});
},
}
);
}
package main;
use POE;
my $done = 0;
POE::Component::Normal::Workhorse->spawn
( check_end => sub { return $done },
work => sub { print "run once\n" },
context => {},
);
Is it somewhat useful or thorough rubbish?
--
Sincerely,
孙一鸣 Simon Sun
--
Be a man with simple interface.