Skip to content

Commit

Permalink
saving __SUB__ in a variable for later use
Browse files Browse the repository at this point in the history
  • Loading branch information
Sadrak committed Aug 14, 2021
1 parent e0afa09 commit bd5b030
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Mojolicious/Guides/Cookbook.pod
Original file line number Diff line number Diff line change
Expand Up @@ -1413,12 +1413,15 @@ to process requests in smaller batches.
# Stop if there are no more URLs
return unless my $url = shift @urls;

# Save __SUB__ for later use in another callback
my $fetch = __SUB__;

# Fetch the next title
$ua->get($url => sub ($ua, $tx) {
say "$url: ", $tx->result->dom->at('title')->text;

# Next request
__SUB__->();
$fetch->();
$promise->resolve if --$count == 0;
});
$count++;
Expand Down

0 comments on commit bd5b030

Please sign in to comment.