File tree Expand file tree Collapse file tree 4 files changed +19
-3
lines changed
Expand file tree Collapse file tree 4 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ abstract public function pop(int $timeout): mixed;
1717 abstract public function count (): int ;
1818
1919 /**
20- * Execute a callback with lock protection
20+ * Execute a callback with lock protection if the adapter supports it
2121 *
2222 * @param callable $callback
2323 * @param int $timeout Timeout in seconds
Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ public function push(mixed $connection): static
2323 return $ this ;
2424 }
2525
26+ /**
27+ * @param int $timeout Stack adapter will ignore timeout
28+ * @return mixed
29+ */
2630 public function pop (int $ timeout ): mixed
2731 {
2832 return array_pop ($ this ->pool );
@@ -33,6 +37,12 @@ public function count(): int
3337 return count ($ this ->pool );
3438 }
3539
40+ /**
41+ * No lock applied and just the callback is executed
42+ * @param callable $callback
43+ * @param int $timeout
44+ * @return mixed
45+ */
3646 public function withLock (callable $ callback , int $ timeout ): mixed
3747 {
3848 return $ callback ();
Original file line number Diff line number Diff line change @@ -45,6 +45,12 @@ public function count(): int
4545 return is_int ($ length ) ? $ length : 0 ;
4646 }
4747
48+ /**
49+ * Executes the callback under a lock and releases it afterward.
50+ * @param callable $callback
51+ * @param int $timeout
52+ * @return mixed
53+ */
4854 public function withLock (callable $ callback , int $ timeout ): mixed
4955 {
5056 // Acquire lock for thread-safe operations with timeout to prevent deadlock
Original file line number Diff line number Diff line change @@ -419,7 +419,7 @@ public function destroy(?Connection $connection = null): static
419419 */
420420 public function isEmpty (): bool
421421 {
422- return $ this ->pool -> count () === 0 ;
422+ return $ this ->count () === 0 ;
423423 }
424424
425425 /**
@@ -440,6 +440,6 @@ private function recordPoolTelemetry(): void
440440 $ this ->telemetryActiveConnections ->record ($ activeConnections , $ this ->telemetryAttributes );
441441 $ this ->telemetryIdleConnections ->record ($ idleConnections , $ this ->telemetryAttributes );
442442 $ this ->telemetryOpenConnections ->record ($ openConnections , $ this ->telemetryAttributes );
443- $ this ->telemetryPoolCapacity ->record ($ activeConnections + $ this ->pool -> count () , $ this ->telemetryAttributes );
443+ $ this ->telemetryPoolCapacity ->record ($ this ->connectionsCreated , $ this ->telemetryAttributes );
444444 }
445445}
You can’t perform that action at this time.
0 commit comments