Hi,

At the risk of making a nuisance of myself, I'd like to ask another
question (two this week!). I wrote some code that sets an alarm for an
event that is actually handled by another session. This doesn't work,
and it took me a while to figure out what, exactly, wasn't working
<laugh>.

My question is, what's the recommended way to post alarmed or delayed
events between sessions? Because the alarm and delay methods are
kernel methods, I naively assumed that they would "magically" dispatch
to the session I wanted them to go to. There are lots of ways I could
kludge this (post an event to a 'set_an_alarm_for_me' state in the
session I want the alarm to be set in, etc). But I'm wondering if I'm
missing some obvious bit of syntax or an idiom that makes this easy.

In case I haven't explained this well, I'm attaching a bit of test
scriptage that indicates what I'd kind of like to do.

Thanks,
Kwindla

----

#!/usr/bin/perl -w
use POE;

use strict;
use warnings;
$|++;

POE::Session->create
  ( inline_states =>
    { _start => sub {
        $poe_kernel->alias_set ( 'receiver' );
        print "starting event receiver and sending an initial test event\n";
        $poe_kernel->alarm_set ( alarmist => 0, 'test from myself' );
      },
      alarmist => sub {
        my $what = $_[ARG0];
        print "got alarm event - $what\n";
      }
    } );

POE::Session->create
  ( inline_states =>
    { _start => sub {
        print "starting event sender\n";
        $poe_kernel->alarm_set ( send_to_other => 1 );
      },
      send_to_other => sub {
        print "trying to set alarm for 'receiver'; ";
        print "this won't actually ever work\n";
        $poe_kernel->alarm_set ( alarmist => 0, 'from another session' );
        $poe_kernel->alarm_set ( send_to_other => time+1 );
      }
    } );

$poe_kernel->run;
exit 0;

Reply via email to