with-lock-hidden-from-recursion-check
ErrorsCollection

with-lock-hidden-from-recursion-check

Synthesised documentation from type/Lock/Async

From type/Lock/Async

See Original text in context

method with-lock-hidden-from-recursion-check(&code)

Temporarily resets the Lock::Async recursion list so that it no longer includes the lock this method is called on and runs the given &code immediately if the call to the method occurred in a caller chain where protect-or-queue-on-recursion has already been called and the lock has been placed on the recursion list.

my Lock::Async $lock .= new;
my Int         $count = 0;
 
$lock.protect-or-queue-on-recursion({
    my Int $count = 0;
 
    # Runs instantly. 
    $lock.with-lock-hidden-from-recursion-check({
        $count++;
    });
 
    # Runs after the outer caller's protect-or-queue-on-recursion call has 
    # finished running. 
    $lock.protect-or-queue-on-recursion({
        $count++;
    }).then({
        say $count# OUTPUT: 2 
    });
 
    say $count# OUTPUT: 1 
});