Skip to content

stevan/Acktor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

__  __  _________        _    _
\ \ \ \ \______/ \______| | _| |_ ___  _ __
 \ \ \ \ \____/ _ \ / __| |/ / __/ _ \| '__|
 / / / / /___/ ___ \ (__|   <| || (_) | |
/_/ /_/ /___/_/   \_\___|_|\_\\__\___/|_|

YAAAAAM4P

Yet Another Attempt At An Actor Model For Perl.

Example

use Acktor;
use Acktor::System;
use Acktor::Behaviors;

class Pong :isa(Acktor) {
    field $ping;

    method Start :Receive {
        $ping = sender;
        $ping->send( event *Ping::Ping, 0 );
    }

    method Pong :Receive ($count) {
        $ping->send( event *Ping::Ping, $count );
    }
}

class Ping :isa(Acktor) {
    field $max_bounce :param;
    field $pong;

    method Start :Receive {
        $pong = spawn Props[ Pong:: ];
        $pong->send( event *Pong::Start );
    }

    method Ping :Receive ($count) {
        $count++;

        if ( $count <= $max_bounce ) {
            $pong->send( event *Pong::Pong, $count );
        } else {
            context->stop(context->self); # will stop $pong as well
        }
    }
}

sub init ($ctx) {
    my $Ping = spawn Props[ Ping::, ( max_bounce => 5 ) ];
    $Ping->send( event *Ping::Start );
}

Acktor::System->new
              ->loop( init => \&init );

About

An Actor Model for Perl

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages