NAME
Zing::Process - Processing Unit
ABSTRACT
Processing Unit and Actor Abstraction
SYNOPSIS
use Zing::Process;
my $process = Zing::Process->new;
# $process->execute;
DESCRIPTION
This package provides an actor abstraction which serve as a cooperative concurrent computational unit in an actor-model architecture.
LIBRARIES
This package uses type constraints from:
ATTRIBUTES
This package has the following attributes:
cleanup
cleanup(Str)
This attribute is read-only, accepts (Str)
values, and is optional.
data
data(Data)
This attribute is read-only, accepts (Data)
values, and is optional.
journal
journal(Channel)
This attribute is read-only, accepts (Channel)
values, and is optional.
log
log(Logger)
This attribute is read-only, accepts (Logger)
values, and is optional.
logic
logic(Logic)
This attribute is read-only, accepts (Logic)
values, and is optional.
loop
loop(Loop)
This attribute is read-only, accepts (Loop)
values, and is optional.
mailbox
mailbox(Mailbox)
This attribute is read-only, accepts (Mailbox)
values, and is optional.
meta
meta(Meta)
This attribute is read-only, accepts (Meta)
values, and is optional.
name
name(Name)
This attribute is read-only, accepts (Name)
values, and is optional.
on_perform
on_perform(Maybe[CodeRef])
This attribute is read-only, accepts (Maybe[CodeRef])
values, and is optional.
on_receive
on_receive(Maybe[CodeRef])
This attribute is read-only, accepts (Maybe[CodeRef])
values, and is optional.
parent
parent(Maybe[Process])
This attribute is read-only, accepts (Maybe[Process])
values, and is optional.
pid
pid(Int)
This attribute is read-only, accepts (Int)
values, and is optional.
signals
signals(HashRef[Str|CodeRef])
This attribute is read-only, accepts (HashRef[Str|CodeRef])
values, and is optional.
started
started(Int)
This attribute is read-only, accepts (Int)
values, and is optional.
stopped
stopped(Int)
This attribute is read-only, accepts (Int)
values, and is optional.
tag
tag(Str)
This attribute is read-only, accepts (Str)
values, and is optional.
METHODS
This package implements the following methods:
defer
defer(HashRef $data) : Object
The defer method allows a process to sends a message to itself for later processing.
destroy
destroy() : Object
The destroy method de-registers the process and drops the process-specific data stores.
execute
execute() : Object
The execute method executes the process event-loop indefinitely.
exercise
exercise() : Object
The exercise method executes the event-loop but stops after one iteration.
metadata
metadata() : HashRef
The metadata method returns metadata specific to the process.
ping
ping(Int $pid) : Bool
The ping method returns truthy if the process of the PID provided is active.
receive
receive(Str $from, HashRef $data) : Any
The receive method, when not overloaded, executes the callback in the "on_receive" attribute for each cycle of the event loop.
- receive example #1
-
# given: synopsis $process = Zing::Process->new( on_receive => sub { my ($self, $from, $data) = @_; [$from, $data]; }, ); $process->receive($process->term, { ping => 1 });
recv
recv() : Maybe[HashRef]
The recv method is a proxy for "recv" in Zing::Mailbox and receives a single new message from the mailbox.
- recv example #2
-
# given: synopsis my $peer = Zing::Process->new; $peer->send($process, { note => 'ehlo' }); $process->recv;
reply
reply(HashRef $bag, HashRef $value) : Int
The reply method is a proxy for "reply" in Zing::Mailbox and sends a message to the mailbox represented by the $bag
received.
-
# given: synopsis my $peer = Zing::Process->new; $peer->send($process, { note => 'ehlo' }); my $mail = $process->recv; $process->reply($mail, { note => 'helo' });
send
send(Mailbox | Process | Str $to, HashRef $data) : Int
The send method is a proxy for "send" in Zing::Mailbox and sends a new message to the mailbox specified.
- send example #1
-
# given: synopsis my $peer = Zing::Process->new; $process->send($peer, { note => 'invite' });
- send example #2
-
# given: synopsis my $peer = Zing::Process->new; $process->send($peer->mailbox, { note => 'invite' });
- send example #3
-
# given: synopsis my $peer = Zing::Process->new; $process->send($peer->mailbox->term, { note => 'invite' });
shutdown
shutdown() : Object
The shutdown method haults the process event-loop immediately.
signal
signal(Int $pid, Str $type = 'kill') : Int
The signal method sends a kill
signal to the process of the PID provided.
spawn
spawn(Scheme $scheme) : Fork
The spawn method forks a scheme and returns a Zing::Fork handler.
term
term() : Str
The term method generates a term (safe string) for the datastore.
winddown
winddown() : Object
The winddown method haults the process event-loop after the current iteration.
AUTHOR
Al Newkirk, awncorp@cpan.org
LICENSE
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".