From: Matt S Trout Date: Fri, 11 Nov 2011 10:55:00 +0000 (+0000) Subject: switch to local-izing on_result in await_all X-Git-Tag: v0.001001~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b1aab0cf42d520d69d4bd8cc8f7cc86d7d21f6d9;p=scpubgit%2FTak.git switch to local-izing on_result in await_all --- diff --git a/lib/Tak.pm b/lib/Tak.pm index 1e0de48..dfa1930 100644 --- a/lib/Tak.pm +++ b/lib/Tak.pm @@ -20,15 +20,18 @@ sub await_all { return unless @requests; my %req = map +("$_" => "$_"), @requests; my $done; - my %orig; my %on_r = map { - my $orig = $orig{$_} = $_->{on_result}; + my $orig = $_->{on_result}; my $tag = $req{$_}; ($_ => sub { delete $req{$tag}; $orig->(@_); $done = 1 unless keys %req; }) } @requests; - $_->{on_result} = $on_r{$_} for @requests; - $class->loop_until($done); - $_->{on_result} = $orig{$_} for @requests; + my $call = sub { $class->loop_until($done) }; + foreach (@requests) { + my $req = $_; + my $inner = $call; + $call = sub { local $req->{on_result} = $on_r{$req}; $inner->() }; + } + $call->(); return; }