public function __invoke() { while ($this->now() < $this->timeout) { yield; } $this->channel->put(true); }
function fibonacci($c, $quit) { $x = 0; $y = 1; while (true) { list($value, $channel) = (yield Channel::any([$c, $x], $quit)); switch ($channel) { case $c: $tmp = $x + $y; $x = $y; $y = $tmp; break; case $quit: echo $value; return; } } }
<?php require_once '../../vendor/autoload.php'; use CrystalPlanet\Redshift\Redshift; use CrystalPlanet\Redshift\Channel\Channel; Redshift::run(function () { $channel = new Channel(); // Write 'foo' to a channel (yield $channel->write('foo')); // Read 'foo' from a channel $message = (yield $channel->read()); // Print 'foo' echo $message . PHP_EOL; });