Skip to content

Commit 254f061

Browse files
committed
Exponentially increase delay
1 parent 23dbdbc commit 254f061

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/AsyncClient.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ final class AsyncClient
2929
*/
3030
protected $channels = [];
3131

32+
/**
33+
* @var int
34+
*/
35+
protected $delay = 200;
36+
3237
/**
3338
* @param LoopInterface $loop
3439
* @param string $app Application ID
@@ -61,8 +66,10 @@ public static function create(LoopInterface $loop, string $app, Resolver $resolv
6166
public function __construct(WebsocketClient $client)
6267
{
6368
//Only create one connection and share the most recent among all subscriber
64-
$this->client = $client->retryWhen(function (Observable $errors) {
65-
return $this->handleLowLevelError($errors);
69+
$this->client = $client->retryWhen(function (Observable $errors) {
70+
return $errors->flatMap(function (Throwable $throwable) {
71+
return $this->handleLowLevelError($throwable);
72+
});
6673
})->shareReplay(1);
6774
$this->messages = $this->client
6875
->flatMap(function (MessageSubject $ms) {
@@ -131,14 +138,10 @@ public function send(array $message)
131138
});
132139
}
133140

134-
private function handleLowLevelError(Observable $errors)
141+
private function handleLowLevelError(Throwable $throwable)
135142
{
136-
$stream = $errors->subscribe(
137-
function (Throwable $throwable) use (&$stream) {
138-
echo (string)$throwable, PHP_EOL;
139-
}
140-
);
143+
$this->delay *= 2;
141144
echo __LINE__, ': ', time(), PHP_EOL;
142-
return $errors->delay(200);
145+
return Observable::timer($this->delay);
143146
}
144147
}

0 commit comments

Comments
 (0)