use strict; use POE; use POE::Session; POE::Session->create( inline_states => { _start => \&start, #_start is automagicaly the first event continue => \&looping #user defined event we will call later } ); $poe_kernel->run(); sub start { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Starting in 5!\n"; $kernel->delay( continue => 5 ); # call the continue event in five seconds } sub looping { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; $heap->{counter}++; #the heap is just a hash we can put goodies in. print "$heap->{counter} iteration!\n"; if ($heap->{counter} < 10) { $kernel->delay( continue => 1 ); #start state continue in 1 seconds } } #### use strict; use POE; use POE::Session; POE::Session->create( inline_states => { _start => \&start, #_start is automagicaly the first event continue => \&looping #user defined event we will call later } ); POE::Session->create( inline_states => { _start => \&start2, #_start is automagicaly the first event continue => \&looping2 #user defined event we will call later } ); $poe_kernel->run(); sub start { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Starting A in 5! (Loops every .5 seconds) \n"; $kernel->delay( continue => 5 ); # call the continue event in five seconds } sub looping { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; $heap->{counter}++; #the heap is just a hash we can put goodies in. print "A: $heap->{counter} iteration! \n"; if ($heap->{counter} < 100) { $kernel->delay( continue => .5 ); #start state continue in 1 seconds } } sub start2 { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Starting B in 7 (Loops every 2 seconds)!\n"; $kernel->delay( continue => 7 ); # call the continue event in five seconds } sub looping2 { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; $heap->{counter}++; #the heap is just a hash we can put goodies in. print "B: Iteration number $heap->{counter}!\n"; if ($heap->{counter} < 100) { $kernel->delay( continue => 2 ); #start state continue in 1 seconds } }