Skip to content

Commit

Permalink
Release locks synchronously
Browse files Browse the repository at this point in the history
Only release locks asynchronously on implicit unlock by the destructor.

Fixes #22.
  • Loading branch information
kelunik committed Jul 13, 2022
1 parent d9c5ae7 commit 707c74a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amp\Sync;

use Revolt\EventLoop;
use function Amp\async;

/**
* A handle on an acquired lock from a synchronization object.
Expand Down Expand Up @@ -45,8 +45,10 @@ public function release(): void
}

// Invoke the releaser function given to us by the synchronization source to release the lock.
EventLoop::queue($this->release);
$release = $this->release;
$this->release = null;

$release();
}

/**
Expand All @@ -55,7 +57,7 @@ public function release(): void
public function __destruct()
{
if (!$this->isReleased()) {
$this->release();
async($this->release(...));
}
}
}

0 comments on commit 707c74a

Please sign in to comment.