Is the order of the values returned by await
always relative to the input order?
my @aoa = (
qw<1 a>, qw<2 b>, qw<3 c>,
qw<4 d>, qw<5 e>, qw<6 f>,
qw<7 g>, qw<8 h>, qw<9 i>,
);
my @portions = ( ( 0, 2 ), ( 3, 5 ), ( 6, 8 ) );
my @promise;
for @portions -> $range {
@promise.push: start {
do for $range[0] .. $range[1] -> $row {
do for ^@aoa.[$row] -> $col {
my $str = @aoa[$row][$col] // '';
$row, $col, $str;
}
}
};
}
for await @promise -> @portion {
for @portion -> @p_rows {
say @p_rows.join( ', ' );
}
}
Yes, the slurpy form of await
is explicitly designed so that one can do things like:
my ($spec, $config) = await start { load-yaml slurp $spec-file },
start { from-json slurp $config-file };
And have the correct things assigned, without regard to which completes first. In the case in the question - pushing Promise
s onto an array - then the result order will match the order of those Promise
s, even if a latter one completes sooner in time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With