/** * @param int $count * @return void */ public function produceNext($count = 1) { if ($this->completed) { return; } for ($i = 0; $i < $count; $i++) { if (!$this->isIteratorValid()) { $this->completed = true; $this->obs->onCompleted(); return; } $this->obs->onNext($this->iterator->current()); $this->iterator->next(); } }
/** * */ public function onCompleted() { if ($this->valueSet) { parent::onNext($this->value); } parent::onCompleted(); }
private function startConnection() { $loop = \EventLoop\getLoop(); $dnsResolverFactory = new Factory(); $dnsResolver = $dnsResolverFactory->createCached('8.8.8.8', $loop); $factory = new \React\HttpClient\Factory(); $client = $factory->create($loop, $dnsResolver); $cNegotiator = new ClientNegotiator($this->url, $this->subProtocols); $headers = $cNegotiator->getRequest()->getHeaders(); $flatHeaders = []; foreach ($headers as $k => $v) { $flatHeaders[$k] = $v[0]; } $request = $client->request("GET", $this->url, $flatHeaders, '1.1'); $request->on('response', function (Response $response, Request $request) use($cNegotiator) { if ($response->getCode() !== 101) { throw new \Exception("Unexpected response code " . $response->getCode()); } // TODO: Should validate response //$cNegotiator->validateResponse($response); $subprotoHeader = ""; $psr7Response = new \GuzzleHttp\Psr7\Response($response->getCode(), $response->getHeaders(), null, $response->getVersion()); if (count($psr7Response->getHeader('Sec-WebSocket-Protocol')) == 1) { $subprotoHeader = $psr7Response->getHeader('Sec-WebSocket-Protocol')[0]; } parent::onNext(new MessageSubject(new AnonymousObservable(function (ObserverInterface $observer) use($response) { $response->on('data', function ($data) use($observer) { $observer->onNext($data); }); $response->on('error', function ($e) use($observer) { $observer->onError($e); }); $response->on('close', function () use($observer) { $observer->onCompleted(); }); $response->on('end', function () use($observer) { $observer->onCompleted(); // complete the parent observer - we only do 1 connection parent::onCompleted(); }); return new CallbackDisposable(function () use($response) { // commented this out because disposal was causing the other // end (the request) to close also - which causes the pending messages // to get tossed //$response->close(); }); }), new CallbackObserver(function ($x) use($request) { $request->write($x); }, function ($e) use($request) { $request->close(); }, function () use($request) { $request->end(); }), true, $this->useMessageObject, $subprotoHeader, $cNegotiator->getRequest(), $psr7Response)); }); $request->writeHead(); }
public function onCompleted() { if (!$this->isDisposed()) { parent::onCompleted(); $this->dispose(); } }
public function onCompleted() { $this->stream->end(); parent::onCompleted(); }
/** * @test * @expectedException RuntimeException */ public function it_passes_on_complete_if_disposed() { $subject = new Subject(); $subject->dispose(); $subject->onCompleted(); }
public function onCompleted() { $this->sendFrame($this->createCloseFrame()); // notify subscribers parent::onCompleted(); }