Could you show me how to modify this to provide a tasks completed progress indicator per the example above?

#!/usr/bin/perl use warnings; use strict; use POE qw(Wheel::Run Filter::Reference); sub MAX_CONCURRENT_TASKS () { 3 } my @tasks = qw(one two three four five six seven eight nine ten); POE::Session->create( inline_states => { _start => \&start_tasks, next_task => \&start_tasks, task_result => \&handle_task_result, task_done => \&handle_task_done, task_debug => \&handle_task_debug, sig_child => \&sig_child, } ); sub start_tasks { my ($kernel, $heap) = @_[KERNEL, HEAP]; while (keys(%{$heap->{task}}) < MAX_CONCURRENT_TASKS) { my $next_task = shift @tasks; last unless defined $next_task; print "Starting task for $next_task...\n"; my $task = POE::Wheel::Run->new( Program => sub { do_stuff($next_task) }, StdoutFilter => POE::Filter::Reference->new(), StdoutEvent => "task_result", StderrEvent => "task_debug", CloseEvent => "task_done", ); $heap->{task}->{$task->ID} = $task; $kernel->sig_child($task->PID, "sig_child"); } } sub do_stuff { binmode(STDOUT); # Required for this to work on MSWin32 my $task = shift; my $filter = POE::Filter::Reference->new(); sleep(rand 5); my %result = ( task => $task, status => "seems ok to me", ); my $output = $filter->put([\%result]); print @$output; } sub handle_task_result { my $result = $_[ARG0]; print "Result for $result->{task}: $result->{status}\n"; } sub handle_task_debug { my $result = $_[ARG0]; print "Debug: $result\n"; } sub handle_task_done { my ($kernel, $heap, $task_id) = @_[KERNEL, HEAP, ARG0]; delete $heap->{task}->{$task_id}; $kernel->yield("next_task"); } sub sig_child { my ($heap, $sig, $pid, $exit_val) = @_[HEAP, ARG0, ARG1, ARG2]; my $details = delete $heap->{$pid}; # warn "$$: Child $pid exited"; } $poe_kernel->run(); exit 0;

In reply to Re^2: Implement Queue mechanism in Perl by Anonymous Monk
in thread Implement Queue mechanism in Perl by doubledecker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.