Created
November 15, 2024 18:16
-
-
Save bo-tato/3e273c47aa9499c1464652d8b01df88b to your computer and use it in GitHub Desktop.
concurrent requests with supply.throttle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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