/** * @test */ public function await_default_timeout() { $start = microtime(true); $observable = Observable::never()->takeUntil(Observable::timer(2000)); $generator = \Rx\await($observable); foreach ($generator as $item) { } $totalTime = microtime(true) - $start; $this->assertEquals('2', round($totalTime)); }
<?php require __DIR__ . '/../vendor/autoload.php'; $source = \Rx\Observable::interval(1000)->take(5); //Take the first 5 $generator = \Rx\await($source); foreach ($generator as $item) { echo $item, PHP_EOL; } echo "DONE";
<?php //This example requires https://github.com/RxPHP/RxHttp require __DIR__ . '/../vendor/autoload.php'; $terms = ["rxphp", "php", "make php great again"]; $search = \Rx\Observable::fromArray($terms)->map(function ($term) { return urlencode($term); })->flatMap(function ($term) { return \Rx\React\Http::get("http://www.google.com/search?q={$term}")->map(function ($result) use($term) { return ["term" => $term, "page" => $result]; }); }); $generator = \Rx\await($search); echo "BLOCKING", PHP_EOL; foreach ($generator as $item) { echo "Result page for: {$item['term']}", PHP_EOL, $item['page']; } echo "DONE";