我想在fasync
下面使用类似于threads async
. 我是否忘记了什么,是否有一些此处未涵盖的极端案例?
sub fasync(&) {
my ($worker) = @_;
my $pid = fork() // die "can't fork!";
if (!$pid) {
$worker->();
exit(0);
}
return sub {
my ($flags) = @_;
return waitpid($pid, $flags // 0);
}
}
my @join = map {
my $job = $_;
fasync {
print "$job\n";
};
} 1 .. 10;
$_->() for @join;