Skip to content

Instantly share code, notes, and snippets.

@leedo
Created October 27, 2011 18:55
Show Gist options
  • Select an option

  • Save leedo/1320474 to your computer and use it in GitHub Desktop.

Select an option

Save leedo/1320474 to your computer and use it in GitHub Desktop.
Condvar zen
sub post_download {
my ($self, $body, $cb) = @_;
my $data = decode_json $body;
my $gist = $data->{gists}[0];
my $cv = AE::cv;
while (my $file = shift @{$gist->{files}}) {
$cv->begin;
http_request get => "http://gist.github.com/raw/$gist->{repo}/$file", sub {
my ($body, $headers) = @_;
push @{$gist->{files}}, [$file, $body];
$cv->end;
}
}
$cv->cb(sub {$cb->($gist)});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment