From 0c281291d92a057b5027101ee39ff231fdda127d Mon Sep 17 00:00:00 2001 From: Nigel Horne Date: Tue, 15 Nov 2016 16:39:21 -0500 Subject: [PATCH] More playing with the threads implementation --- Makefile.PL | 1 + lib/Data/Fetch.pm | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index e20b171..a8d6d81 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -29,6 +29,7 @@ WriteMakefile( }, PREREQ_PM => { 'Coro' => 0, + # 'threads' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Data-Fetch-*' }, diff --git a/lib/Data/Fetch.pm b/lib/Data/Fetch.pm index 4acb709..2e644b8 100755 --- a/lib/Data/Fetch.pm +++ b/lib/Data/Fetch.pm @@ -87,16 +87,15 @@ sub prime { if($self->{values} && $self->{values}->{$object} && $self->{values}->{$object}->{status}) { return $self; } + # $self->{values}->{$object}->{thread} = threads->create(sub { - # my $o = shift; - # my $m = shift; - # if(my $a = shift) { + # my ($o, $m, $a) = @_; + # if($a) { # return eval '$o->$m($a)'; # } # return eval '$o->$m()'; - # }, $args{'object'}, $args{'message'}, $args{'arg'}); + # }, ($args{object}, $args{message}, $args{arg})); - $self->{values}->{$object}->{status} = 'running'; $self->{values}->{$object}->{thread} = async { my $o = $args{object}; my $m = $args{message}; @@ -106,6 +105,7 @@ sub prime { return eval '$o->$m()'; }; + $self->{values}->{$object}->{status} = 'running'; return $self; # Easily prime lots of values in one call } @@ -160,7 +160,9 @@ sub DESTROY { foreach my $o(values %{$self->{values}}) { if($o->{thread}) { - # $o->{thread}->detach(); + # if($o->{thread}->is_running()) { + # $o->{thread}->detach(); + # } delete $o->{thread}; delete $o->{value}; }