| Conditions | 5 |
| Paths | 2 |
| Total Lines | 29 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | protected function sarRun(Pool $pool, string $method, array $arguments, Promised $interrupter = null) |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var Poolable $conn |
||
| 30 | */ |
||
| 31 | $conn = null; |
||
| 32 | |||
| 33 | // MUST use defer because it can exec whatever job be FIN or KILL |
||
| 34 | // otherwise conn will never be released |
||
| 35 | yield defer(function ($stage) use (&$conn) { |
||
| 36 | if ($conn instanceof Poolable) { |
||
| 37 | $stage instanceof Broken ? $conn->destroy() : $conn->release(); |
||
| 38 | } elseif ($stage instanceof Poolable) { |
||
| 39 | $stage->release(); |
||
| 40 | } |
||
| 41 | }); |
||
| 42 | |||
| 43 | // pick out |
||
| 44 | $conn = yield $pool->select(); |
||
| 45 | |||
| 46 | // check interrupter |
||
| 47 | if ($interrupter) { |
||
| 48 | $interrupter->then(function () use ($conn) { |
||
| 49 | return $conn; |
||
| 50 | }); |
||
| 51 | } |
||
| 52 | |||
| 53 | // execute |
||
| 54 | return yield $conn->$method(...$arguments); |
||
| 55 | } |
||
| 57 |