Home > Archive > PERL POE > August 2005 > alarms (or delays) to other sessions
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
alarms (or delays) to other sessions
|
|
| Kwindla Hultman Kramer 2005-08-21, 2:58 am |
|
Hi,
At the risk of making a nuisance of myself, I'd like to ask another
question (two this w !). 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;
| |
| Tim Cheadle 2005-08-21, 2:58 am |
| > My question is, what's the recommended way to post alarmed or delayed
> events between sessions?
You are correct; the documentation clearly states that the alarm and delay
interfaces are only for the current session. Perhaps methods should be
added to add alarms that post to other sessions.
As a workaround, either set up an alarm in the local session whose event
posts to the remote session, or post an event to the remote session that
itself sets the appropriate alarm.
Tim
|
|
|
|
|