my @promises; for 0..13 { push @promises, start {say $_;sleep 1;} if @promises == 4 { await Promise.allof(@promises); @promises = []; } } await @promises;
每 4 个线程, 就先等待返回线程返回。
时间: 2024-11-13 08:37:53
my @promises; for 0..13 { push @promises, start {say $_;sleep 1;} if @promises == 4 { await Promise.allof(@promises); @promises = []; } } await @promises;
每 4 个线程, 就先等待返回线程返回。