Skip to content

Commit 1360aaa

Browse files
authored
Merge pull request #466 from Jay04653/userdata_exit_from_loop_after_socket_closed
userData: exit from loop after socket closed or not connected
2 parents 6dc9265 + 8719669 commit 1360aaa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

php-binance-api.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ public function userData(&$balance_callback, &$execution_callback = false)
26332633

26342634
// @codeCoverageIgnoreStart
26352635
// phpunit can't cover async function
2636-
$connector($this->getWsEndpoint() . $this->listenKey)->then(function ($ws) {
2636+
$connector($this->getWsEndpoint() . $this->listenKey)->then(function ($ws) use ($loop) {
26372637
$ws->on('message', function ($data) use ($ws) {
26382638
if ($this->subscriptions['@userdata'] === false) {
26392639
//$this->subscriptions[$endpoint] = null;
@@ -2652,13 +2652,15 @@ public function userData(&$balance_callback, &$execution_callback = false)
26522652
}
26532653
}
26542654
});
2655-
$ws->on('close', function ($code = null, $reason = null) {
2655+
$ws->on('close', function ($code = null, $reason = null) use ($loop) {
26562656
// WPCS: XSS OK.
26572657
echo "userData: WebSocket Connection closed! ({$code} - {$reason})" . PHP_EOL;
2658+
$loop->stop();
26582659
});
2659-
}, function ($e) {
2660+
}, function ($e) use ($loop) {
26602661
// WPCS: XSS OK.
26612662
echo "userData: Could not connect: {$e->getMessage()}" . PHP_EOL;
2663+
$loop->stop();
26622664
});
26632665

26642666
$loop->run();

0 commit comments

Comments
 (0)