Re: Newbie question about sessions
"Chris 'BinGOs' Williams" <[email protected]>
| Newsgroups | gmane.comp.lang.perl.poe |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Oct 07, 2008 at 05:35:34PM +0200, Artem Harutyunyan wrote:
> Hi Alex,
>
> >
> > POE::Kernel->post ('worker' => 'random');
> > POE::Kernel->run();
>
> Yes, that works. However this doesn't solve my problem. I want session
> to stay alive and wait for (possible) future events. (I will need that
> when I will use my class inside a server).
>
> Artem.
The POE Kernel will only continue to work if there is work to do, be it
events, alarms, etc.
Under normal circumstances, say you have other sessions active and things
like events and alarms flying about setting an alias on a session is good
enough to make that session stay around ( ie. not be reaped by the kernel ).
If there are sessions which are only 'held alive' by an alias and there is
no other work going on, the kernel will reap these sessions and eventually
terminate.
Observe:
[canker:~]$ cat poereap.pl
use strict;
use warnings;
use POE;
for ( 0 .. 10 ) {
POE::Session->create(
inline_states => {
_start => sub { warn "Starting 'meep$_'\n"; $poe_kernel->alias_set("meep$_"); return; },
_stop => sub { warn "We stopped\n"; return; },
},
);
}
$poe_kernel->run();
exit 0;
[canker:~]$ perl poereap.pl
Starting 'meep0'
Starting 'meep1'
Starting 'meep2'
Starting 'meep3'
Starting 'meep4'
Starting 'meep5'
Starting 'meep6'
Starting 'meep7'
Starting 'meep8'
Starting 'meep9'
Starting 'meep10'
We stopped
We stopped
We stopped
We stopped
We stopped
We stopped
We stopped
We stopped
We stopped
We stopped
We stopped
[canker:~]$
Your session will either have to do some work, create a wheel, trigger some events/alarms, etc. or you can
explicitly increase the reference count using the kernel's refcount_increment() method.
With the latter, your session will stay around until you explicitly decrease the reference count for your
session using refcount_decrement() method.
--
Chris Williams
aka BinGOs
PGP ID 0x4658671F
http://www.gumbynet.org.uk
==========================
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQFI64rf7eyMi0ZYZx8RAmKrAJ0Wv6Pj+CLd+Kk7QwjdBuE9f9J6SgCfV1rx Xr7YiT5UZzRmf/IW3cSiwgs= =YJyg -----END PGP SIGNATURE-----