@@ -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