jfroebe has asked for the wisdom of the Perl Monks concerning the following question:
When I call $_[KERNEL]->alarm() twice referencing two events from within an event that itself is called by $_[KERNEL]->alarm().
_start -> (alarm to wakeup event). wakeup event -> ( alarms to wokeup event and wakeup event). This works as I would expect.
When I call the alarm to wakeup before the alarm to wokeup, the wokeup event is never called.
works:
#!/usr/bin/perl use strict; use warnings; use POE; use Time::HiRes qw(time); POE::Session->create ( inline_states => { _start => sub { $_[KERNEL]->alias_set('timer'); $_[KERNEL]->post('timer', 'wakeup'); }, wakeup => sub { print "wakeup at ", scalar localtime(), "\n"; $[KERNEL]->alarm( wokeup => int( time() ) + 2 ); $[KERNEL]->alarm( wakeup => int( time() ) + 2 ); }, wokeup => sub { print "wokeup at ", scalar localtime(), "\n"; }, }, ); POE::Kernel->run(); exit 0;
jason@jfroebe-laptop:~/bin$ ./test_poe.pl wakeup at Tue Jul 1 20:30:56 2008 wokeup at Tue Jul 1 20:30:58 2008 wakeup at Tue Jul 1 20:30:58 2008 wokeup at Tue Jul 1 20:31:00 2008
wokeup is never called:
#!/usr/bin/perl use strict; use warnings; use POE; use Time::HiRes qw(time); POE::Session->create ( inline_states => { _start => sub { $_[KERNEL]->alias_set('timer'); $_[KERNEL]->post('timer', 'wakeup'); }, wakeup => sub { print "wakeup at ", scalar localtime(), "\n"; $_[KERNEL]->alarm( wakeup => int( time() ) + 2 ); $_[KERNEL]->alarm( wokeup => int( time() ) + 2 ); }, wokeup => sub { print "wokeup at ", scalar localtime(), "\n"; }, }, ); POE::Kernel->run(); exit 0;
jason@jfroebe-laptop:~/bin$ ./test_poe.pl wakeup at Tue Jul 1 19:36:29 2008 wakeup at Tue Jul 1 19:36:31 2008 wakeup at Tue Jul 1 19:36:33 2008
My understanding is that $_[KERNEL]->alarm() sets the alarm and moves on. Apparently it isn't when the alarm is set to the event that it is currently in. That, or I'm misunderstanding $_[KERNEL]->alarm(). Am I close?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: POE::Session - why does alarm order matter?
by rcaputo (Chaplain) on Jul 02, 2008 at 02:04 UTC | |
by jfroebe (Parson) on Jul 02, 2008 at 02:14 UTC |