All pastes #1624228 Raw Edit

clueless

public text v1 · immutable
#1624228 ·published 2009-10-16 21:33 UTC
rendered paste body
use strict;use warnings;use POE;use MooseX::Declare;use Data::Dumper;class MyJob with POEx::WorkerPool::Role::Job{        # this method is executed across the process boundary	method init_job    {		my $self = shift;        # Multi step jobs are supported and even reported on, so just keep         # enqueuing steps        $self->enqueue_step (        	[            	sub {					return 1;					# do some work here				},        		[qw/1/]        	]    	);	}}class NeedsParallelJobExecution{	with 'POEx::Role::SessionInstantiation';    use aliased 'POEx::Role::Event';    use POEx::WorkerPool::Types(':all');    use POEx::WorkerPool::WorkerEvents(':all');	use POEx::Types(':all');    use POEx::WorkerPool;		use Data::Dumper;    has pool => (		 is => 'ro',		 isa => DoesWorkerPool,		 lazy_build => 1	);    method _build_pool { 		my $self = shift;			return POEx::WorkerPool->new(			options => $self->options,		)	};    after _start is Event    {		my $self = shift;        for(0..4)        {                # we get back the alias of the worker with which our job was                 # enqueued            my $alias = $self->pool->enqueue_job(MyJob->new());                # we can subscribe to all sorts of events that the worker                # generates but for the simple case, we just want to know our                # jobs are done                #                # See POEx::PubSub for more information            $self->post            (                $alias, 'subscribe',                 event_name => +PXWP_JOB_COMPLETE,            	event_handler => 'job_complete',        	);    	}	};    method job_complete (SessionID :$worker_id, Str :$job_id, Ref :$msg) is Event    {    	print "Worker($worker_id) finished Job($job_id)\n";    }}my $thing = NeedsParallelJobExecution->new();POE::Kernel->run();