Skip to content

Commit

Permalink
Updated docblock for LockInterface (#698)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
huangdijia and huangdijia committed Aug 7, 2024
1 parent ef6cc6b commit 9730bd7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/lock/src/Driver/AbstractLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract public function release(): bool;

/**
* Attempt to acquire the lock.
* @return mixed
* {@inheritdoc}
*/
#[Override]
public function get(?callable $callback = null)
Expand All @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion src/lock/src/Driver/LockInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 9730bd7

Please sign in to comment.