我可以使用 Hyper 并行执行,并且它可以工作:
$ raku -e 'race for (^8).race(batch => 1, degree => 4) {sleep rand; .say}'
0
3
5
2
1
7
4
6
但是我怎样才能将收集/获取行为添加到这样的循环中?
在这种方法中,take 不会检测到它被包裹在 gather 上下文中:
$ raku -e '
my @x = gather race for (^8).race(batch => 1, degree => 4) {
sleep rand;
take $_;
};
@x.say
'
Died at:
take without gather
在这种方法中,gather 将消耗 HyperSeq 而不会真正对其进行“超级处理”:
$ raku -e '
my @x = race gather for (^8).race(batch => 1, degree => 4) {
sleep rand;
take $_;
};
@x.say
'
[0 1 2 3 4 5 6 7]