# Detect if PHP generator accepts send()?

- Thread: https://externals.io/message/111295
- Original archive: https://news-web.php.net/php.internals/111295
- Started by olleharstedt@gmail.com on 2020-08-03T08:48:09+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #111295 — olleharstedt@gmail.com — 2020-08-03T08:48:09+00:00

URL: https://externals.io/message/111295#111295

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
