Rx\Scheduler\EventLoopScheduler::start PHP Method

start() public method

public start ( )
    public function start()
    {
        $this->clock = $this->now();
        $this->insideInvoke = true;
        while ($this->queue->count() > 0) {
            $next = $this->getNext();
            if ($next !== null) {
                if ($next->getDueTime() > $this->clock) {
                    $this->nextTimer = $next->getDueTime();
                    $timerCallable = $this->timerCallable;
                    $timerCallable($this->nextTimer - $this->clock, [$this, "start"]);
                    break;
                }
                $next->inVoke();
            }
        }
        $this->insideInvoke = false;
    }

Usage Example

コード例 #1
0
 public function testSchedulerWorkedWithScheduledEventOutsideItself()
 {
     $loop = Factory::create();
     $scheduler = new EventLoopScheduler($loop);
     $scheduler->start();
     $start = microtime(true);
     $called = null;
     $loop->addTimer(0.1, function () use($scheduler, &$called) {
         $scheduler->schedule(function () use(&$called) {
             $called = microtime(true);
         }, 100);
     });
     $loop->run();
     $this->assertEquals(0.2, $called - $start, '', 0.02);
 }