Skip to content

Commit 8e37f2a

Browse files
committed
Refactor read watcher
1 parent 60d57ad commit 8e37f2a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/PgSqlExecutor.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ public function __construct($handle, $socket) {
4646
$listeners = &$this->listeners;
4747

4848
$this->poll = Loop::onReadable($socket, static function ($watcher) use (&$deferred, &$listeners, $handle) {
49-
$status = \pg_consume_input($handle);
49+
if (!\pg_consume_input($handle)) {
50+
if ($deferred !== null) {
51+
$deferred->fail(new FailureException(\pg_last_error($handle)));
52+
}
53+
return;
54+
}
5055

5156
while ($result = \pg_get_notify($handle, \PGSQL_ASSOC)) {
5257
$channel = $result["message"];
@@ -66,13 +71,13 @@ public function __construct($handle, $socket) {
6671
return; // No active query, only notification listeners.
6772
}
6873

69-
if (!$status) {
70-
$deferred->fail(new FailureException(\pg_last_error($handle)));
71-
} elseif (!\pg_connection_busy($handle)) {
72-
$deferred->resolve(\pg_get_result($handle));
74+
if (\pg_connection_busy($handle)) {
75+
return;
7376
}
7477

75-
if (!\pg_connection_busy($handle) && empty($listeners)) {
78+
$deferred->resolve(\pg_get_result($handle));
79+
80+
if (empty($listeners)) {
7681
Loop::disable($watcher);
7782
}
7883
});

0 commit comments

Comments
 (0)