Skip to content

Commit 6516e8a

Browse files
committed
Refactor to start sending request immediately without unneeded timer
1 parent e48f586 commit 6516e8a

2 files changed

Lines changed: 105 additions & 302 deletions

File tree

src/EventSource.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,10 @@ public function __construct($url, LoopInterface $loop, Browser $browser = null)
9393
$this->url = $url;
9494

9595
$this->readyState = self::CONNECTING;
96-
97-
$this->timer = $loop->addTimer(0, function () {
98-
$this->timer = null;
99-
$this->send();
100-
});
96+
$this->request();
10197
}
10298

103-
private function send()
99+
private function request()
104100
{
105101
$headers = array(
106102
'Accept' => 'text/event-stream',
@@ -160,7 +156,7 @@ private function send()
160156
$this->readyState = self::CONNECTING;
161157
$this->timer = $this->loop->addTimer($this->reconnectTime, function () {
162158
$this->timer = null;
163-
$this->send();
159+
$this->request();
164160
});
165161
}
166162
});
@@ -180,7 +176,7 @@ private function send()
180176

181177
$this->timer = $this->loop->addTimer($this->reconnectTime, function () {
182178
$this->timer = null;
183-
$this->send();
179+
$this->request();
184180
});
185181
});
186182
}

0 commit comments

Comments
 (0)