-callback中的附加代码:content_cb
会减慢下载速度吗?
假设附加代码需要 1_000/1_000_000 秒才能运行并且回调被调用 1_000 次,那会减慢 1_000/1_000_000 * 1_000 秒的下载速度吗?
#!/usr/bin/env perl
use warnings;
use 5.012;
use Time::HiRes qw(usleep);
use File::Basename;
use LWP::UserAgent;
my $url = 'my_url';
my $file_name = basename $url;
my $ua = LWP::UserAgent->new();
open my $fh, '>>:raw', $file_name or die $!;
my $res = $ua->get(
$url,
':content_cb' => sub {
my ( $chunk, $res, $proto ) = @_;
print $fh $chunk;
usleep( 1000 ); # code substitute
},
);
close $fh;