-
-
Save davidwdan/ccbf3c9d4724fa9dfd92f60775c3f041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Amp\Artax\Response; | |
use Rx\Observable; | |
use Amp\Artax\Client; | |
Amp\execute(function () { | |
$sitesObs = Observable::defer(function () { | |
return Observable::fromPromise((new Client)->request('https://google.com')); | |
})->retryWhen(function (Observable $errors) { | |
return $errors->take(3)->delay(1000); | |
}); | |
//Every 1 second make the | |
$codesObs = Observable::interval(1000) | |
->flatMapTo($sitesObs) | |
->map(function (Response $response) { | |
return $response->getStatus(); | |
}) | |
->take(3) | |
->toArray() | |
->map('json_encode'); | |
echo yield $codesObs->toPromise(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment