nextcallee
ErrorsCollection

nextcallee

Synthesised documentation from language/functions

From language/functions

See Original text in context

Redispatch may be required to call a block that is not the current scope what provides nextsame and friends with the problem to referring to the wrong scope. Use nextcallee to capture the right candidate and call it at the desired time.

proto pick-winner(|) {*}
 
multi pick-winner (Int \s{
    my &nextone = nextcallee;
    Promise.in(π²).then: { nextone s }
}
multi pick-winner { say "Woot! $^w won" }
 
with pick-winner ^5 .pick -> \result {
    say "And the winner is...";
    await result;
}
 
# OUTPUT: 
# And the winner is... 
# Woot! 3 won 

The Int candidate takes the nextcallee and then fires up a Promise to be executed in parallel, after some timeout, and then returns. We can't use nextsame here, because it'd be trying to nextsame the Promise's block instead of our original routine.