Skip to content

Instantly share code, notes, and snippets.

@bo-tato
Created November 15, 2024 18:16
Show Gist options
  • Save bo-tato/3e273c47aa9499c1464652d8b01df88b to your computer and use it in GitHub Desktop.
Save bo-tato/3e273c47aa9499c1464652d8b01df88b to your computer and use it in GitHub Desktop.
concurrent requests with supply.throttle
use Cro::HTTP::Client;
my @urls = 'https://httpbin.org/delay/2' xx 200;
my $requests = Supply.from-list(@urls);
my $t = $requests.throttle: 50, {
await Cro::HTTP::Client.get($_);
say "finished a request";
CATCH {
when X::Cro::HTTP::Error {
say "Problem fetching " ~ .request.target;
}
}
}
$t.wait;
say "finished all requests";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment