Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Explain $! and $/ in start block
  • Loading branch information
Altai-man committed May 17, 2019
1 parent 3bbea96 commit 9025ba0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/Language/control.pod6
Expand Up @@ -181,6 +181,22 @@ A C<start> may also be used on a bare statement (without curly braces).
This is mainly just useful when calling a subroutine / method on an object
is the only thing to do asynchronously.
sub get42 { 42 }
my $promise = start get42;
say $promise.result; # OUTPUT: «42␤»
Note that code executed this way does not have access to special variables L«C<$!>|/syntax/$!»
and L«C<$/>|/syntax/$/» of its outer block, but receives new ones.
'a' ~~ /a/; # $/ is set to 「a」
try die; # $! is defined now with an anonymous AdHoc exception
# as a code block
await start { say $! }; # OUTPUT: «Nil␤»
await start { say $/ }; # OUTPUT: «Nil␤»
# as a single statement
await start $!.say; # OUTPUT: «Nil␤»
await start $/.say; # OUTPUT: «Nil␤»
=head1 X<if|control flow,if>
To conditionally run a block of code, use an C<if> followed by a condition.
Expand Down

0 comments on commit 9025ba0

Please sign in to comment.