summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Thread/Task.pm11
-rw-r--r--lib/Thread/Task/Handle.pm2
-rw-r--r--lib/Thread/Task/Manager.pm11
-rw-r--r--lib/Thread/Task/Role/Conduit.pm30
4 files changed, 43 insertions, 11 deletions
diff --git a/lib/Thread/Task.pm b/lib/Thread/Task.pm
index 86a1387..5567805 100644
--- a/lib/Thread/Task.pm
+++ b/lib/Thread/Task.pm
@@ -102,9 +102,14 @@ class Thread::Task {
die "Can't update between different task classes";
}
for my $attr ($self->meta->get_all_attributes) {
- $attr->set_value($self,
- $attr->get_value($new_task)
- );
+ if ($attr->has_value($new_task)) {
+ $attr->set_value($self,
+ $attr->get_value($new_task)
+ );
+ }
+ else {
+ $attr->clear_value($self);
+ }
}
return;
}
diff --git a/lib/Thread/Task/Handle.pm b/lib/Thread/Task/Handle.pm
index 5cb2eed..e3f0eea 100644
--- a/lib/Thread/Task/Handle.pm
+++ b/lib/Thread/Task/Handle.pm
@@ -119,7 +119,7 @@ class Thread::Task::Handle {
}
method stopped() {
- $self->message('__STOPPED__');
+ $self->message('__STOPPED__',$self->task);
}
method on_stopped(Task_T $new_task, @args) {
diff --git a/lib/Thread/Task/Manager.pm b/lib/Thread/Task/Manager.pm
index 1410799..14f6963 100644
--- a/lib/Thread/Task/Manager.pm
+++ b/lib/Thread/Task/Manager.pm
@@ -49,7 +49,6 @@ class Thread::Task::Manager {
_workers_count => 'count',
_set_worker => 'set',
_get_worker => 'get',
- _delete_worker => 'delete',
_workers => 'elements',
},
);
@@ -64,7 +63,6 @@ class Thread::Task::Manager {
_set_handle => 'set',
_get_handle => 'get',
_delete_handle => 'delete',
- _handles => 'elements',
},
);
@@ -74,11 +72,9 @@ class Thread::Task::Manager {
default => sub { {} },
init_arg => undef,
handles => {
- _running_count => 'count',
_set_running => 'set',
_get_running => 'get',
_delete_running => 'delete',
- _running => 'elements',
},
);
@@ -99,7 +95,7 @@ class Thread::Task::Manager {
does => Conduit_T,
);
- method BUILD() {
+ method BUILD(HashRef $params) {
$self->conduit->conduit_init($self);
}
@@ -131,7 +127,8 @@ class Thread::Task::Manager {
}
method stop_thread(Int $worker_id) {
- $self->_delete_worker($worker_id)->stop;
+ my $worker=$self->_get_worker($worker_id);
+ $worker->stop;
}
method next_thread() {
@@ -173,7 +170,7 @@ class Thread::Task::Manager {
my $worker = $self->next_thread or return;
$worker->hid($hid);
- $handle->wid($worker->wid);
+ #$handle->wid($worker->wid);
$worker->send(task => $handle->as_array);
diff --git a/lib/Thread/Task/Role/Conduit.pm b/lib/Thread/Task/Role/Conduit.pm
new file mode 100644
index 0000000..1ffbd04
--- /dev/null
+++ b/lib/Thread/Task/Role/Conduit.pm
@@ -0,0 +1,30 @@
+use 5.008003;
+use MooseX::Declare;
+
+role Thread::Task::Role::Conduit {
+ use MooseX::Types::Moose qw(ClassName);
+ use Thread::Task::Types qw(Manager_T);
+ use Carp;
+
+ requires 'signal';
+
+ has manager => (
+ isa => Manager_T,
+ is => 'ro',
+ required => 0,
+ writer => '_set_manager',
+ predicate => '_has_manager',
+ );
+
+ method conduit_init(Manager_T $manager) {
+ $self->_set_manager($manager);
+ }
+
+ before signal {
+ if (!$self->_has_manager) {
+ croak "Can't signal without a manager";
+ }
+ }
+}
+
+1;