Skip to content

Commit

Permalink
More playing with the threads implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Nov 15, 2016
1 parent 0fa1d18 commit 0c28129
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions Makefile.PL
Expand Up @@ -29,6 +29,7 @@ WriteMakefile(
},
PREREQ_PM => {
'Coro' => 0,
# 'threads' => 0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Data-Fetch-*' },
Expand Down
14 changes: 8 additions & 6 deletions lib/Data/Fetch.pm
Expand Up @@ -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};
Expand All @@ -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
}

Expand Down Expand Up @@ -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};
}
Expand Down

0 comments on commit 0c28129

Please sign in to comment.