From 9730bd760e832894429c3a2c1673d70492bffefa Mon Sep 17 00:00:00 2001 From: Deeka Wong Date: Wed, 7 Aug 2024 13:15:43 +0800 Subject: [PATCH] Updated docblock for `LockInterface` (#698) * Updated docblock for `LockInterface` * feat: Refactor `LockInterface` and `AbstractLock` to handle lock timeouts The code changes in `LockInterface.php` and `AbstractLock.php` refactor the lock functionality to handle lock timeouts. This includes adding a `LockTimeoutException` and updating the `block` method to throw this exception when the lock cannot be acquired within the specified time. This change improves the reliability and error handling of the lock mechanism. Note: This message has been generated based on the provided code changes and recent commits. --------- Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com> --- src/lock/src/Driver/AbstractLock.php | 5 ++--- src/lock/src/Driver/LockInterface.php | 11 ++++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lock/src/Driver/AbstractLock.php b/src/lock/src/Driver/AbstractLock.php index 0c1e18039..a314c04b8 100644 --- a/src/lock/src/Driver/AbstractLock.php +++ b/src/lock/src/Driver/AbstractLock.php @@ -52,7 +52,7 @@ abstract public function release(): bool; /** * Attempt to acquire the lock. - * @return mixed + * {@inheritdoc} */ #[Override] public function get(?callable $callback = null) @@ -72,8 +72,7 @@ public function get(?callable $callback = null) /** * Attempt to acquire the lock for the given number of seconds. - * @return mixed - * @throws LockTimeoutException + * {@inheritdoc} */ #[Override] public function block(int $seconds, ?callable $callback = null) diff --git a/src/lock/src/Driver/LockInterface.php b/src/lock/src/Driver/LockInterface.php index 22f9f459e..c852c2d24 100644 --- a/src/lock/src/Driver/LockInterface.php +++ b/src/lock/src/Driver/LockInterface.php @@ -11,16 +11,25 @@ namespace FriendsOfHyperf\Lock\Driver; +use FriendsOfHyperf\Lock\Exception\LockTimeoutException; + interface LockInterface { /** * Attempt to acquire the lock. - * @return mixed + * @template T + * @param (callable(): T)|null $callback + * @return ($callback is null ? bool : T) */ public function get(?callable $callback = null); /** * Attempt to acquire the lock for the given number of seconds. + * + * @template T + * @param (callable(): T)|null $callback + * @return ($callback is null ? bool : T) + * @throws LockTimeoutException */ public function block(int $seconds, ?callable $callback = null);