Skip to content

Commit

Permalink
hotfixes (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
kra authored Feb 3, 2020
1 parent fdad8e4 commit 3dcdbb4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Snowflake.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ public function next()
{
$timestamp = $this->timestamp();

if ($timestamp < static::$lastTimestamp) {
if ($timestamp < $this->lastTimestamp) {
if (!$this->startTimeout) {
$this->startTimeout = $timestamp;
}

if (($timestamp - $this->startTimeout) < $this->timeout) {
usleep(static::$lastTimestamp - $timestamp);
usleep($this->lastTimestamp - $timestamp);
return $this->next();
}

$errorLog = "[Timeout({$this->timeout})] Couldn't generation snowflake id, os time is backwards. [last timestamp:" . static::$lastTimestamp ."]";
$errorLog = "[Timeout({$this->timeout})] Couldn't generation snowflake id, os time is backwards. [last timestamp:" . $this->lastTimestamp ."]";
throw new Exception($errorLog);
}

Expand Down

0 comments on commit 3dcdbb4

Please sign in to comment.