update page now
Laravel Live Japan

Voting

: three plus six?
(Example: nine)

The Note You're Voting On

info at boukeversteegh dot nl
9 years ago
Here's how to detect loop breaks, and how to handle or cleanup after an interruption.

<?php
    function generator()
    {
        $complete = false;
        try {

            while (($result = some_function())) {
                yield $result;
            }
            $complete = true;

        } finally {
            if (!$complete) {
                // cleanup when loop breaks 
            } else {
                // cleanup when loop completes
            }
        }

        // Do something only after loop completes
    }
?>

<< Back to user notes page

To Top