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?

Jason L. Froebe

Blog, Tech Blog


In reply to POE::Session - why does alarm order matter? by jfroebe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.