Acme-Ghost

 view release on metacpan or  search on metacpan

eg/ghost_ae.pl  view on Meta::CPAN

package MyGhost;

use parent 'Acme::Ghost';
use AnyEvent;

sub startup {
    my $self = shift;
    my $quit = AnyEvent->condvar;
    my $i = 0;

    # Create watcher timer
    my $watcher = AnyEvent->timer (after => 1, interval => 1, cb => sub {
        $quit->send unless $self->ok;
    });

    # Create process timer
    my $timer = AnyEvent->timer(after => 3, interval => 3, cb => sub {
        $self->log->info("Tick! " . ++$i);
        $quit->send if $i >= 10;
    });

    $self->log->debug("Start AnyEvent");
    $quit->recv; # Run!
    $self->log->debug("Finish AnyEvent");
}

1;

eg/ghost_ioloop.pl  view on Meta::CPAN


sub init {
    my $self = shift;
    $self->{loop} = Mojo::IOLoop->new;
}
sub startup {
    my $self = shift;
    my $loop = $self->{loop};
    my $i = 0;

    # Add a timers
    my $timer = $loop->timer(5 => sub {
        my $l = shift; # loop
        $self->log->info("Timer!");
    });
    my $recur = $loop->recurring(1 => sub {
        my $l = shift; # loop
        $l->stop unless $self->ok;
        $self->log->info("Tick! " . ++$i);
        $l->stop if $i >= 10;
    });

eg/prefork_ioloop.pl  view on Meta::CPAN

sub init {
    my $self = shift;
    $self->{loop} = Mojo::IOLoop->new;
}
sub spirit {
    my $self = shift;
    my $loop = $self->{loop};
    my $max = 10;
    my $i = 0;

    # Add a timers
    my $timer = $loop->timer(5 => sub {
        my $l = shift; # loop
        $self->log->info("Timer!");
    });

    my $recur = $loop->recurring(1 => sub {
        my $l = shift; # loop
        $l->stop unless $self->tick;
        $self->log->debug(sprintf("$$> %d/%d", ++$i, $max));
        $l->stop if $i >= $max;
    });

lib/Acme/Ghost.pm  view on Meta::CPAN


    sub init {
        my $self = shift;
        $self->{loop} = Mojo::IOLoop->new;
    }
    sub startup {
        my $self = shift;
        my $loop = $self->{loop};
        my $i = 0;

        # Add a timers
        my $timer = $loop->timer(5 => sub {
            my $l = shift; # loop
            $self->log->info("Timer!");
        });
        my $recur = $loop->recurring(1 => sub {
            my $l = shift; # loop
            $l->stop unless $self->ok;
            $self->log->info("Tick! " . ++$i);
            $l->stop if $i >= 10;
        });

lib/Acme/Ghost.pm  view on Meta::CPAN

    package MyGhost;

    use parent 'Acme::Ghost';
    use AnyEvent;

    sub startup {
        my $self = shift;
        my $quit = AnyEvent->condvar;
        my $i = 0;

        # Create watcher timer
        my $watcher = AnyEvent->timer (after => 1, interval => 1, cb => sub {
            $quit->send unless $self->ok;
        });

        # Create process timer
        my $timer = AnyEvent->timer(after => 3, interval => 3, cb => sub {
            $self->log->info("Tick! " . ++$i);
            $quit->send if $i >= 10;
        });

        $self->log->debug("Start AnyEvent");
        $quit->recv; # Run!
        $self->log->debug("Finish AnyEvent");
    }

    1;

lib/Acme/Ghost/Prefork.pm  view on Meta::CPAN

    sub init {
        my $self = shift;
        $self->{loop} = Mojo::IOLoop->new;
    }
    sub spirit {
        my $self = shift;
        my $loop = $self->{loop};
        my $max = 10;
        my $i = 0;

        # Add a timers
        my $timer = $loop->timer(5 => sub {
            my $l = shift; # loop
            $self->log->info("Timer!");
        });

        my $recur = $loop->recurring(1 => sub {
            my $l = shift; # loop
            $l->stop unless $self->tick;
            $self->log->debug(sprintf("$$> %d/%d", ++$i, $max));
            $l->stop if $i >= $max;
        });



( run in 0.589 second using v1.01-cache-2.11-cpan-49f99fa48dc )