Uri Guttman > Stem-0.11 > Stem::Gather

Download:
Stem-0.11.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  5
Open  0
View/Report Bugs
Source   Latest Release: Stem-0.12

Description ^

This is a object module used by Stem Cells and objects to detect when a set of asynchronous events have finished. It is constructed by an owner object which then stores it in itselt. Gather objects are initialized with a set of keys to be gathered. When the owner object is notified of an event, it calls the gathered method of the gather object with a list of keys. When all of the keys are gathered, a callback is made to the owner object. An optional timeout is available which will also generate a callback if the keys are not gathered in time.

Synopsis ^

        use Stem::Gather ;

        # $self is the owner object that has already been created

        my $gather = Stem::Gather->new(
                'object'        => $self,
                'keys'          => [qw( msg1 msg2 )]
        ) ;

        $self->{'gather'} = $gather ;

        sub msg1_in {

                my( $self ) = @_ ;
                $self->{'gather'}->gathered( 'msg1' ) ;
        }

        sub msg2_in {

                my( $self ) = @_ ;
                $self->{'gather'}->gathered( 'msg2' ) ;
        }

        sub gather_done {

                my( $self ) = @_ ;

                print "we have gathered\n" ;
        }

Constructor Attributes for Class Stem::Gather

Method new

This is the constructor method for Stem::Gather. It uses the standard Stem key/value API with the

Method restart

This method is called to start up the gather object when it has already gathered all the keys, it has timed out or it was never started (the no_start attribute was enabled). It takes no arguments.

Method add_keys

This method is passed a list of keys which will be added to the list to be watched for by the Stem::Gather object. The new keys are not looked for until a call to the restart method is made.

Method gathered

This method is called with a list of keys that are gathered. The keys that haven't been gathered before are marked as gathered. If there are no more keys to be gathered, the method in the gathered_method attribute is called in the owner object. You have to call the restart method on this gather object to use it again.You can pass this methods keys that have been gathered or are not even in the list to be gathered and they are ignored.

Method

This method must be called if the owner object is being shut down or destroyed. It will cancel any pending timeout and break the link back to the owner object. The owner object can then be destroyed without leaking memory.

syntax highlighting: