Detect if PHP generator accepts send()?
| From: | Olle Härstedt | Date: | Mon, 03 Aug 2020 08:48:09 +0000 |
| Subject: | Detect if PHP generator accepts send()? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-111295@lists.php.net to get a copy of this message | ||
Hi!
Is it possible to somehow detect if a generator can accept any send()
command? That is, if it has any line like this:
$gen = yield;
Use-case is when generators are used to factor out side-effects (as in
redux-saga). If no expression depends on the result of any
side-effect, all side-effects can be run concurrently (non-blocking
IO). Otherwise, the code should wait.
Example:
yield $io->db->query('UPDATE table ...'); // Don't wait, run as async
$result = yield $io->db->query('SELECT id FROM ...'); // Wait for result
I've looked into Amphp but didn't find any way to do this yet. Maybe
async()/await() functions (not language constructs) would work?
Thank you for any feedback.
Olle