Monday 27 June 2016

php - rethinkdb changes() with yield doesn't return value

function fetchProduct()

{
$cursor = r\table("tableOne")->changes()->run($conn);

foreach ($cursor as $product) {
yield $product;
}
}


$product = fetchProduct();

var_dump($product);
echo "i"; //when the function use yield, this line executed. But when return used, it doesn't come to this line.


I understand rethinkdb's changes() will keep listening to the changes so i found that its better to use yield over the $cursor. But the yield doesn't return value to the calling party. But when return is used value returned.



How to make the yield to return any value when changes occur?



References:
https://rethinkdb.com/docs/async-connections/
What does yield mean in PHP?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...