The output of this code:

```php
function gen() {
    $rows = ['a', 'b', 'c'];

    foreach ($rows as $row) {
        echo "yield $row\n";
        yield $row;
    }

    echo "finished\n";
}

foreach (gen() as $v) {
    echo "val $v\n";
    // break;
}

```

is

```
yield a
val a
yield b
val b
yield c
val c
finished

```

With the break uncommeted is:

```
yield a
val a

```

So if I break the loop, the code after the loop in gen() function is not executed. I need clean some resources, but I don't know how to do it.

For example, here:

```php
public function getRows(string $query, array $pameters = []): \Generator
{
    $stmt = $this->pdo->prepare($query);

    // bind pameters...

    $stmt->execute();

    while ($row = $stmt->fetch()) {
        $item = $this->something($row);
        yield $item;
    }

    $stmt->closeCursor(); // this code is not executed if a break is called
}

```

Or a function who reads a file and the cursor should be closed at the end:

```php
$cursor = openFileCursor('myfile.txt')
while ($line = $cursor->getLine()) {
    $item = someFunction($line);
    yield $item
}
closeFileCursor($cursor);

```

Any idea?