Phive\Queue\Tests\TimeUtils::callAt PHP Method

callAt() public static method

public static callAt ( $timestamp, Closure $func, $forceSleep = null )
$func Closure
    public static function callAt($timestamp, \Closure $func, $forceSleep = null)
    {
        if (!function_exists('uopz_function')) {
            $forceSleep = true;
        }
        if ($forceSleep) {
            sleep(-time() + $timestamp);
            return $func();
        }
        self::setTime($timestamp);
        try {
            $result = $func();
        } catch (\Exception $e) {
            self::unsetTime();
            throw $e;
        }
        self::unsetTime();
        return $result;
    }

Usage Example

Exemplo n.º 1
0
 public function testPopDelay()
 {
     $eta = time() + 3;
     $this->queue->push('item', $eta);
     $this->assertNoItemIsAvailable($this->queue);
     TimeUtils::callAt($eta, function () {
         $this->assertEquals('item', $this->queue->pop());
     }, !$this->supportsExpiredEta);
 }