Skip to content

Commit cdf2a42

Browse files
authored
Document temp's behaviour with delayed reads
1 parent 5286362 commit cdf2a42

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

doc/Language/operators.pod6

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,33 @@ You can also assign immediately as part of the call to temp:
11951195
temp $a = "five";
11961196
=end code
11971197
1198+
Be warned the C<temp> effects get removed once the block is left. If
1199+
you were to access the value from, say, within a L<Promise> after
1200+
the C<temp> was undone, you'd get the original value, not the C<temp> one:
1201+
1202+
=begin code
1203+
my $v = "original";
1204+
{
1205+
temp $v = "new one";
1206+
start {
1207+
say "[PROMISE] Value before block is left: `$v`";
1208+
sleep 1;
1209+
say "[PROMISE] Block was left while we slept; value is now `$v`";
1210+
}
1211+
sleep ½;
1212+
say "About to leave the block; value is `$v`";
1213+
}
1214+
say "Left the block; value is now `$v`";
1215+
sleep 2;
1216+
1217+
# OUTPUT:
1218+
# [PROMISE] Value before block is left: `new one`
1219+
# About to leave the block; value is `new one`
1220+
# Left the block; value is now `original`
1221+
# [PROMISE] Block was left while we slept; value is now `original`
1222+
=end code
1223+
1224+
11981225
=head2 prefix C«let»
11991226
12001227
sub prefix:<let>(Mu $a is rw)

0 commit comments

Comments
 (0)