Argon::Client
use Argon::Client; # Connect my $client = Argon::Client->new(host => '...', port => XXXX); # Send task and wait for result my $the_answer = $client->queue(sub { my ($x, $y) = @_; return $x * $y; }, [6, 7]); # Send task and get a deferred result that can be synchronized later my $deferred = $client->defer(sub { my ($x, $y) = @_; return $x * $y; }, [6, 7]); my $result = $deferred->(); # Close the client connection $client->shutdown;
Establishes a connection to an Argon network and provides methods for executing tasks and collecting the results.
Creates a new Argon::Client. The connection is made lazily when the first call to "queue" or "connect" is performed. The connection can be forced by calling "connect".
Connects to the remote host.
Sends a task to the Argon network to evaluate $f-(@$args)> and returns the result. Since Argon uses Coro, this method does not actually block until the result is received. Instead, it yields execution priority to other threads until the result is available.
$f-
If an error occurs in the execution of $f, an error is thrown.
$f
Similar to "queue", but instead of waiting for the result, returns an anonymous function that, when called, waits and returns the result. If an error occurs when calling <$f>, it is re-thrown from the anonymous function.
Disconnects from the Argon network.
Storable is used to serialize code that is sent to the Argon network. This means that the code sent will not have access to variables and modules outside of itself when executed. Therefore, the following will not work:
my $x = 0; $client->queue(sub { return $x + 1 }); # $x not found!
The right way is to pass it to the function as part of the task's arguments:
my $x = 0; $client->queue(sub { my $x = shift; return $x + 1; }, [$x]);
Similarly, module imports are not available to the function:
use Data::Dumper; my $data = [1,2,3]; my $string = $client->queue(sub { my $data = shift; return Dumper($data); # Dumper not found }, [$data]);
The right way is to import the module inside the task:
my $data = [1,2,3]; my $string = $client->queue(sub { use Data::Dumper; my $data = shift; return Dumper($data); # Dumper not found }, [$data]);
Jeff Ober <jeffober@gmail.com>
To install Argon, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Argon
CPAN shell
perl -MCPAN -e shell install Argon
For more information on module installation, please visit the detailed CPAN module installation guide.