NAME

Coro::MP - erlang-style multi-processing/message-passing framework

SYNOPSIS

use Coro::MP;

# exports everything that AnyEvent::MP exports as well.
# new stuff compared to AnyEvent::MP:

# creating/using ports from threads
my $port = port_async {
   # thread context, $SELF is set to $port

   # returning will "kil" the $port with an empty reason
};

# attach to an existing port
spawn $NODE, "::initfunc";
sub ::initfunc {
   rcv_async $SELF, sub {
      ...
   };
}

# simple "tag" receives:
my ($pid) = get "pid", 30
   or die "no pid message received after 30s";

# conditional receive
my ($tag, @data) = get_cond { $_[0] =~ /^group1_/ };
my @next_msg = get_cond { 1 } 30; # 30s timeout

# run thread in port context
peval_async $port, {
   die "kill the port\n";
};

# synchronous "cal"
my @retval = syncol 30, $port, tag => $data;

DESCRIPTION

This module (-family) implements a simple message passing framework.

Despite its simplicity, you can securely message other processes running on the same or other hosts, and you can supervise entities remotely.

This module depends heavily on AnyEvent::MP, in fact, many functions exported by this module are identical to AnyEvent::MP functions. This module family is simply the Coro API to AnyEvent::MP.

Care has been taken to stay compatible with AnyEvent::MP, even if sometimes this required a less natural API (spawn should indeed spawn a thread, not just call an initfunc for example).

For an introduction to AnyEvent::MP, see the AnyEvent::MP::Intro manual page.

VARIABLES/FUNCTIONS

NODE, $NODE, node_of, configure
$SELF, *SELF, SELF, %SELF, @SELF...
snd, mon, kil, psub

These variables and functions work exactly as in AnyEvent::MP, in fact, they are exactly the same functions, and are used in much the same way.

rcv

This function works exactly as AnyEvent::MP::rcv, and is in fact compatible with Coro::MP ports. However, the canonical way to receive messages with Coro::MP is to use get or get_cond.

port

This function is exactly the same as AnyEvent::MP::port and creates new ports. You can attach a thread to them by calling rcv_async or you can do a create and attach in one operation using port_async.

peval

This function works exactly as AnyEvent::MP::psub - you could use it to run callbacks within a port context (good for monitoring), but you cannot get messages unless the callback executes within the thread attached to the port.

Since creating a thread with port context requires somewhta annoying syntax, there is a peval_async function that handles that for you - note that within such a thread, you still cannot get messages.

spawn

This function is identical to AnyEvent::MP::spawn. This means that it doesn't spawn a new thread as one would expect, but simply calls an init function. The init function, however, can attach a new thread easily:

sub initfun {
   my (@args) = @_;

   rcv_async $SELF, sub {
      # thread-code
   };
}
cal

This function is identical to AnyEvent::MP::cal. The easiest way to make a synchronous call is to use Coro's rouse functiona���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

1 POD Error

The following errors were encountered while parsing the POD:

Around line 63:

=over without closing =back