Regarding wheel ID vs. reference, I meant it might be better to pass around the client's wheel ID rather than a reference to the wheel itself. As in:

$kernel->yield('keepalive', $io_wheel->ID, $kernel);
and
keepalive => sub { my ( $io_wheel_id, $kernel, $heap ) = @_[ ARG0, KERNEL ]; return unless exists $heap->{clients}{$io_wheel_id}; $heap->{clients}{$io_wheel_id}->put("keepalive"); $kernel->delay( 'keepalive' => 10, $io_wheel_id ); },

It's more work, for you and for the program, but it stops repeating the timer after the client has disconnected. Of course, another way is to make sure that the timer is canceled wherever you are deleting the client. If you find yourself doing that in multiple places, refactor it into a subroutine like:

sub delete_client { my ($kernel, $heap, $io_wheel_id) = @_; delete $heap->{clients}{$io_wheel_id}; $kernel->delay(keepalive => undef); }
which would be called the usual Perlish way
on_connect_error => sub { # Handle client error, including disconnect. my $wheel_id = $_[ARG3]; delete_client(@_[KERNEL, HEAP], $wheel_id); },
It really helps when cleanup gets complex, as it often does when programs evolve and grow.


In reply to Re^3: POE yield not working by rcaputo
in thread POE yield not working by SoulStyle

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.