Skip to content

Commit 1fc36c9

Browse files
doc strings added
1 parent 22a8b38 commit 1fc36c9

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

src/Pools/Adapter/Stack.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ public function push(mixed $connection): static
2424
}
2525

2626
/**
27-
* @param int $timeout Stack adapter will ignore timeout
28-
* @return mixed
27+
* Pop an item from the stack.
28+
*
29+
* Note: The stack adapter does not support blocking operations.
30+
* The `$timeout` parameter is ignored.
31+
*
32+
* @param int $timeout Ignored by the stack adapter.
33+
* @return mixed|null Returns the popped item, or null if the stack is empty.
2934
*/
3035
public function pop(int $timeout): mixed
3136
{
@@ -38,10 +43,14 @@ public function count(): int
3843
}
3944

4045
/**
41-
* No lock applied and just the callback is executed
42-
* @param callable $callback
43-
* @param int $timeout
44-
* @return mixed
46+
* Executes the callback without acquiring a lock.
47+
*
48+
* This implementation does not provide mutual exclusion.
49+
* The `$timeout` parameter is ignored.
50+
*
51+
* @param callable $callback Callback to execute.
52+
* @param int $timeout Ignored.
53+
* @return mixed The value returned by the callback.
4554
*/
4655
public function withLock(callable $callback, int $timeout): mixed
4756
{

src/Pools/Adapter/Swoole.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,38 @@ public function push(mixed $connection): static
3030
return $this;
3131
}
3232

33+
/**
34+
* Pop an item from the pool.
35+
*
36+
* @param int $timeout Timeout in seconds. Use 0 for non-blocking pop.
37+
* @return mixed|false Returns the pooled value, or false if the pool is empty
38+
* or the timeout expires.
39+
*/
3340
public function pop(int $timeout): mixed
3441
{
35-
$result = $this->pool->pop($timeout);
36-
37-
// if pool is empty or timeout occured => result will be false
38-
return $result;
42+
return $this->pool->pop($timeout);
3943
}
4044

41-
4245
public function count(): int
4346
{
4447
$length = $this->pool->length();
4548
return is_int($length) ? $length : 0;
4649
}
4750

4851
/**
49-
* Executes the callback under a lock and releases it afterward.
50-
* @param callable $callback
51-
* @param int $timeout
52-
* @return mixed
53-
*/
52+
* Executes a callback while holding a lock.
53+
*
54+
* The lock is acquired before invoking the callback and is always released
55+
* afterward, even if the callback throws an exception.
56+
*
57+
* @param callable $callback Callback to execute within the critical section.
58+
* @param int $timeout Maximum time (in seconds) to wait for the lock.
59+
* @return mixed The value returned by the callback.
60+
*
61+
* @throws \RuntimeException If the lock cannot be acquired within the timeout.
62+
*/
5463
public function withLock(callable $callback, int $timeout): mixed
5564
{
56-
// Acquire lock for thread-safe operations with timeout to prevent deadlock
5765
$acquired = $this->lock->lockwait($timeout);
5866

5967
if (!$acquired) {

0 commit comments

Comments
 (0)