logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

POE::Component::Schedule - Schedule POE events using DateTime::Set iterators

Acknowledgment & History

       This module was a friendly fork of POE::Component::Cron to extract the generic parts and isolate the Cron
       specific code in order to reduce dependencies on other CPAN modules.

       See <https://rt.cpan.org/Ticket/Display.html?id=44442>.

       The original author of POE::Component::Cron is Chris Fedde.

       POE::Component::Cron is now implemented as a class that inherits from POE::Component::Schedule.

       Most of the POE::Component::Schedule internals have since been rewritten in 0.91_01 and  we  have  now  a
       complete test suite.

Authors

       Olivier Mengue, "dolmen@cpan.org"
       Chris Fedde, "cfedde@cpan.org"

Description

       This component encapsulates a session that sends events to client sessions on a schedule as defined by a
       DateTime::Set iterator.

Name

       POE::Component::Schedule - Schedule POE events using DateTime::Set iterators

Poe::Component::Schedule Methods

spawn(Alias=>name)
       Start up the PoCo::Schedule background session with the given alias. Returns the back-end session handle.

       No need to call this in normal use, "add()" and "new()" all crank one of these up if it is needed.

   add($session,$event_name,$iterator,@event_args)
           my $sched = POE::Component::Schedule->add(
               $session,
               $event_name,
               $DateTime_Set_iterator,
               @event_args
           );

       Add a set of events to the scheduler.

       Returns a schedule handle. The event is automatically deleted when the handle is not referenced anymore.

   new($session,$event_name,$iterator,@event_args)
       "new()" is an alias for "add()".

Schedule Handle Methods

delete()
       Removes a schedule using the handle returned from "add()" or "new()".

       DEPRECATED: Schedules are now automatically deleted when they are not referenced anymore. So just setting
       the container variable to "undef" will delete the schedule.

See Also

       POE, DateTime::Set, POE::Component::Cron.

Support

       You can look for information at:

       •   RT: CPAN's request tracker

           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-Schedule>: post bug report there.

       •   CPAN Ratings

           <http://cpanratings.perl.org/p/POE-Component-Schedule>:  if  you  use  this  distribution, please add
           comments on your experience for other users.

       •   Search CPAN

           <http://search.cpan.org/dist/POE-Component-Schedule/>

       •   AnnoCPAN: Annotated CPAN documentation

           <http://annocpan.org/dist/POE-Component-Schedule>

Synopsis

           use POE qw(Component::Schedule);
           use DateTime::Set;

           POE::Session->create(
               inline_states => {
                   _start => sub {
                       $_[HEAP]{sched} = POE::Component::Schedule->add(
                           $_[SESSION], Tick => DateTime::Set->from_recurrence(
                               after      => DateTime->now,
                               before     => DateTime->now->add(seconds => 3),
                               recurrence => sub {
                                   return $_[0]->truncate( to => 'second' )->add( seconds => 1 )
                               },
                           ),
                       );
                   },
                   Tick => sub {
                       print 'tick ', scalar localtime, "\n";
                   },
                   remove_sched => sub {
                       # Three ways to remove a schedule
                       # The first one is only for API compatibility with POE::Component::Cron
                       $_[HEAP]{sched}->delete;
                       $_[HEAP]{sched} = undef;
                       delete $_[HEAP]{sched};
                   },
                   _stop => sub {
                       print "_stop\n";
                   },
               },
           );

           POE::Kernel->run();

See Also