-
-
30 Sep 2012 11:28:16 UTC
- Distribution: Thread-Task-Concurrent
- Module version: 0.0103
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues
- Testers (96 / 87 / 6)
- Kwalitee
Bus factor: 1- License: perl_5
- Perl: v5.10.0
- Activity
24 month- Tools
- Download (7.66KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors- Joachim Bargsten <cpan at bargsten dot org>
- Dependencies
- Mouse
- Mouse::Exporter
- Thread::Queue
- threads
- threads::shared
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Thread::Task::Concurrent - Make simple task pocessing simple
SYNOPSIS
use Thread::Task::Concurrent qw(tmsg); my @data = qw(a b c d e f g h i j k l m n o p q); my $tq = Thread::Task::Concurrent->new( task => \&task, max_instances => 4, verbose => 1 ); my $result = $tq->enqueue(@data)->start->join->result; sub task { my $char = shift; # sleep some time my $sleep_time = int rand 10; sleep $sleep_time; #calculate result my $result = "I'm thread " . threads->tid . " and I slept $sleep_time sec. My result was " . $char x 3; return $result; }
DESCRIPTION
If you have input data and you want to pocess it in the same way, Thread::Task::Concurrent gives you an easy to use interface to getthingsdone(TM).
SUBROUTINES
- tmsg($string_message)
- tmsg($string_message, $tid_to_display)
-
Spits out the
$string_message
in the form:[thread_id] <message>
thread_id is by default
threads->tid
, but you can also set it artificially via the$tid_to_display
variable.
METHODS
- Thread::Task::Concurrent->new(%arg)
-
- task => sub { ... }
-
Set the subroutine for the task. Example:
sub { my ($item, $task_arg) = @_; return $result_item; }
- arg => $task_arg
-
Add an additional arg hash/array/scalar to the task/subroutine call.
- max_instances => 4
-
Set the maximum number of threads. Default is 4.
- verbose => 0
-
Switch on/off verbose reporting.
- $ttc = $ttc->start()
-
Start processing.
- $ttc = $ttc->join()
-
Wait for processing end.
- $ttc = $ttc->enqueue(@data)
-
Enqueue items.
- $ttc = $ttc->result()
-
Gather the result.
ACCESSORS
- $q = $ttc->queue
- $rq = $ttc->result_queue
- $task_code_ref = $ttc->task
- $task_arg = $ttc->arg
- $num = $ttc->max_instances
- $threads = $ttc->threads
- $is_verbose = $ttc->verbose
- $is_finished = $ttc->finished
SEE ALSO
-
AUTHOR
jw bargsten,
<cpan at bargsten dot org>
Module Install Instructions
To install Thread::Task::Concurrent, copy and paste the appropriate command in to your terminal.
cpanm Thread::Task::Concurrent
perl -MCPAN -e shell install Thread::Task::Concurrent
For more information on module installation, please visit the detailed CPAN module installation guide.