Hi there,

I'm having a bit of trouble with Alarm timers in Perl POE, I have a program that does a couple of things periodically

However my alarm timers appear to be stomping on one another. The first loop around the wheel they both run they work fine the alert alarm happens at 2, then 4 seconds. Then the Mount alarm triggers at 5 seconds, then they both just start triggering every 2 seconds. I can see I must be stomping on the mounts alarm with the alerts alarm assignment, and I've tried a lot of things like naming the alias different things, naming "next_alarm_time" different things between the subs, naming the subs "tick" and "tock" but nothing seems to work. Any suggestions?

#!/usr/bin/perl use warnings; use strict; use POE qw(Wheel::Run Filter::Reference Wheel::FollowTail); POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->alias_set('MountWatchdog'); $_[HEAP]->{next_alarm_time} = int(time()) + 5; $_[KERNEL]->alarm(tick => $_[HEAP]->{next_alarm_time}); }, tick => sub { my $key; my $name; print "Mount tick at ", time(), "\n"; $_[HEAP]->{next_alarm_time} = $_[HEAP]->{next_alarm_time} + 2; $_[KERNEL]->alarm(tick => $_[HEAP]->{next_alarm_time}); }, }, ); POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->alias_set('AlertWatchdog'); $_[HEAP]->{next_alarm_time} = int(time()) + 2; $_[KERNEL]->alarm(tick => $_[HEAP]->{next_alarm_time}); }, tick => sub { my $key; my $name; print "Alert tick at ", time(), "\n"; $_[HEAP]->{next_alarm_time} = $_[HEAP]->{next_alarm_time} + 2; $_[KERNEL]->alarm(tick => $_[HEAP]->{next_alarm_time}); }, }, ); # Start our POE Kernel. $poe_kernel->run(); exit 0;

In reply to Trying to implement 2 seperate alarm timers in POE by KaiLoi

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.