Exemplo n.º 1
5
 function enableForConsumer($consumerId, $interval, $probeKey)
 {
     $_this = $this;
     $this->enabled = true;
     if (!$this->instant) {
         // register consumer
         $newConsumerId = !isset($this->consumerTimers[$consumerId]);
         if ($interval > 0 && $newConsumerId) {
             $this->consumerTimers[$consumerId] = setInterval(function () use($_this, $consumerId) {
                 $_this->sample($consumerId);
             }, $interval);
         }
         // enable with delayed disabling
         if (!empty($this->disableDelay)) {
             clearTimeout($this->disableDelay);
         }
         $this->disableDelay = setTimeout(function () use($_this) {
             //echo "\ndisabled " . $_this->name;
             $_this->enabled = false;
             foreach ($_this->consumerTimers as $consumerId => $timer) {
                 clearInterval($timer);
             }
             $_this->consumerTimers = array();
         }, PROBE_DISABLE_DELAY);
     }
 }
Exemplo n.º 2
-5
 function testSetInterval()
 {
     $check = 0;
     $intervalId = null;
     $intervalId = setInterval(function () use(&$check, &$intervalId) {
         $check++;
         if ($check > 5) {
             clearInterval($intervalId);
         }
     }, 0.02);
     run();
     $this->assertEquals(6, $check);
 }