Skip to content

Commit c37451a

Browse files
committed
Context::onDestroy
1 parent 56ea4dd commit c37451a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/DatabaseManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
66
use Throwable;
77
use Webman\Context;
8-
use Workerman\Coroutine\Coroutine;
98
use Workerman\Coroutine\Pool;
109

1110
/**
@@ -52,7 +51,8 @@ public function connection($name = null)
5251
$connection = static::$pools[$name]->get();
5352
Context::set($key, $connection);
5453
} finally {
55-
Coroutine::defer(function () use ($connection, $name) {
54+
// We cannot use Coroutine::defer() because we may not be in a coroutine environment currently.
55+
Context::onDestroy(function () use ($connection, $name) {
5656
try {
5757
$connection && static::$pools[$name]->put($connection);
5858
} catch (Throwable) {

0 commit comments

Comments
 (0)