Re: [RFC Discuss] Generator Delegation
| From: | Niklas Keller | Date: | Tue, 03 Mar 2015 10:55:08 +0000 |
| Subject: | Re: [RFC Discuss] Generator Delegation | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-84226@lists.php.net to get a copy of this message | ||
>
> Gr, top-posting...
Sorry, was on mobile. ;-)
However, since the existence of the word "yield" is the only thing that
> marks a coroutine now, how about using a variant of that for the final
> value, e.g. "yield final $foo"?
What's the final value? The last "yield"ed value or a return?
Just to give you some real world example:
If you're using "return", it would look like that:
public function getSession ($sessionId) {
$result = yield $this->redis->get("session.{$sessionId}")); // We're
waiting here until redis responded.
return json_decode($result);
}
Currently, it looks like this:
public function getSession ($sessionId) {
$result = yield $this->redis->get("session.{$sessionId}"));
yield json_decode($result);
}
Or maybe even that:
public function getSession ($sessionId) {
$result = yield $this->redis->get("session.{$sessionId}"));
yield "return" => json_decode($result);
}
I think having the possibility for a return here, would make that code a
lot easier to read and understand.
Regards, Niklas