Skip to content

Commit

Permalink
Merge pull request #15 from always-open/fix/diff-not-absolute
Browse files Browse the repository at this point in the history
Don't use absolute value when checking diff in milliseconds
  • Loading branch information
Quentin Schmick authored Aug 30, 2022
2 parents e537b96 + 4e059a6 commit 7ef2e9c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Jobs/DebouncedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ protected function checkAndWaitUntilReady() : void
$maximum = Cache::get($this->getMaximumWaitTimeKey());
$minimum = Cache::get($this->getMinimumWaitTimeKey());

if (! $maximum) {
if (! $maximum && $minimum) {
while (! $this->minimumWaitComplete()) {
$this->setDebounce();
usleep(self::$MICROSECONDS_SLEEP);
}
}

if (! $minimum) {
if (! $minimum && $maximum) {
while (! $this->maximumWaitComplete()) {
$this->setDebounce();
usleep(self::$MICROSECONDS_SLEEP);
Expand Down Expand Up @@ -190,11 +190,11 @@ protected function getMinimumMillisecondsLeft() : int
$now = now();

if ($minimum && $maximum) {
return min($maximum->diffInMilliseconds($now), $minimum->diffInMilliseconds($now));
return min($now->diffInMilliseconds($maximum, absolute: false), $now->diffInMilliseconds($minimum, absolute: false));
}

if ($minimum) {
return $minimum->diffInMilliseconds($now);
return $now->diffInMilliseconds($minimum, absolute: false);
}

return 0;
Expand All @@ -211,15 +211,15 @@ protected function getMaximumMillisecondsLeft() : int
$now = now();

if ($minimum && $maximum) {
return max($maximum->diffInMilliseconds($now), $minimum->diffInMilliseconds($now));
return max($now->diffInMilliseconds($maximum, absolute: false), $now->diffInMilliseconds($minimum, absolute: false));
}

if ($maximum) {
return $maximum->diffInMilliseconds($now);
return $now->diffInMilliseconds($maximum, absolute: false);
}

if ($minimum) {
return $minimum->diffInMilliseconds($now);
return $now->diffInMilliseconds($minimum, absolute: false);
}

return 0;
Expand Down

0 comments on commit 7ef2e9c

Please sign in to comment.