unlock
ErrorsCollection

unlock

Synthesised documentation from type/Lock type/IO/Handle type/IO/CatHandle type/Lock/Async

From type/Lock

See Original text in context

method unlock(Lock:D:)

Releases the lock.

my $l = Lock.new;
$l.lock;
$l.unlock;

It is important to make sure the Lock is always released, even if an exception is thrown. The safest way to ensure this is to use the protect method, instead of explicitly calling lock and unlock. Failing that, use a LEAVE phaser.

my $l = Lock.new;
{
    $l.lock;
    LEAVE $l.unlock;
}

From type/IO/Handle

See Original text in context

method unlock(IO::Handle:D: --> True)

Removes a lock from the filehandle. It will return True or fail with an exception if it's not possible.

From type/IO/CatHandle

See Original text in context

method unlock(IO::CatHandle:D:)

Same as IO::Handle.unlock. Returns Nil if the source handle queue may get exhausted.

Unlocks only the currently active source handle. The .on-switch method Callable can be used to conveniently lock/unlock the handles as they're being processed by the CatHandle.

From type/Lock/Async

See Original text in context

method unlock(Lock::Async:D: --> Nil)

Releases the lock. If there are any outstanding lock Promises, the one at the head of the queue will then be kept, and potentially code scheduled on the thread pool (so the cost of calling unlock is limited to the work needed to schedule another piece of code that wants to obtain the lock, but not to execute that code).

my $l = Lock::Async.new;
await $l.lock;
$l.unlock;

Prefer to use protect instead of explicit calls to lock and unlock. However, if wishing to use the methods separately, it is wise to use a LEAVE block to ensure that unlock is reliably called. Failing to unlock will mean that nobody can ever lock this particular Lock::Async instance again.

my $l = Lock::Async.new;
{
    await $l.lock;
    LEAVE $l.unlock;
}