public function forExactly($duration) { // what are we doing? $log = usingLog()->startAction("run for exactly '{$duration}'"); // remember the duration // // the $action callback can then make use of it $this->duration = $duration; // convert the duration into seconds $interval = new DateInterval($duration); $seconds = $interval->getTotalSeconds(); // set the alarm pcntl_signal(SIGALRM, array($this, "handleSigAlarm"), FALSE); $log->addStep("setting SIGALRM for '{$seconds}' seconds", function () use($seconds) { pcntl_alarm($seconds); }); declare (ticks=1); $callback = $this->action; $returnVal = $callback($this); // all done $log->endAction(); return $returnVal; }
public function wait($timeout = 'PT01M', $reason = "waiting for everything to catch up") { if (is_string($timeout)) { $interval = new DateInterval($timeout); $seconds = $interval->getTotalSeconds(); } else { $seconds = $timeout; } // what are we doing? $log = usingLog()->startAction("sleeping for {$timeout}; reason is: '{$reason}'"); // zzzzz sleep($seconds); // all done $log->endAction("finished sleeping"); }