lib/Loop/Loop.php
public function setInterval(callable $cb, float $timeout): array
    {
        $keepGoing = true;
        $f = null;

        $f = function () use ($cb, &$f, $timeout, &$keepGoing) {
            if ($keepGoing) {
                $cb();
                $this->setTimeout($f, $timeout);
            }
        };
        $this->setTimeout($f, $timeout);

        // Really the only thing that matters is returning the $keepGoing
        // boolean value.
        //
        // We need to pack it in an array to allow returning by reference.
        // Because I'm worried people will be confused by using a boolean as a
        // sort of identifier, I added an extra string.
        return ['I\'m an implementation detail', &$keepGoing];
    }
public function setInterval(callable $cb, float $timeout): array
    {
        $keepGoing = true;
        $f = null;

        $f = function () use ($cb, &$f, $timeout, &$keepGoing) {
            if ($keepGoing) {
                $cb();
                $this->setTimeout($f, $timeout);
            }
        };
        $this->setTimeout($f, $timeout);

        // Really the only thing that matters is returning the $keepGoing
        // boolean value.
        //
        // We need to pack it in an array to allow returning by reference.
        // Because I'm worried people will be confused by using a boolean as a
        // sort of identifier, I added an extra string.
        return ['I\'m an implementation detail', &$keepGoing];
    }
public function setInterval ( callable $ cb , float $ timeout ) : array { $ keepGoing = true ; $ f = null ; $ f = function ( ) use ( $ cb , & $ f , $ timeout , & $ keepGoing ) { if ( $ keepGoing ) { $ cb ( ) ; $ this -> setTimeout ( $ f , $ timeout ) ; } } ; $ this -> setTimeout ( $ f , $ timeout ) ; // Really the only thing that matters is returning the $keepGoing // boolean value. // // We need to pack it in an array to allow returning by reference. // Because I'm worried people will be confused by using a boolean as a // sort of identifier, I added an extra string. return [ 'I\'m an implementation detail' , & $ keepGoing ] ; }
Executes a function every x seconds.

The value this function returns can be used to stop the interval with
clearInterval.
Executes a function every x seconds .