-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deprecate CoarseTime and replace it with a shortcut implementation
Signed-off-by: Kirill Danshin <k@guava.by>
- Loading branch information
1 parent
4c7269e
commit ef10ed0
Showing
4 changed files
with
18 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,13 @@ | ||
package fasthttp | ||
|
||
import ( | ||
"sync/atomic" | ||
"time" | ||
) | ||
|
||
// CoarseTimeNow returns the current time truncated to the nearest second. | ||
// | ||
// This is a faster alternative to time.Now(). | ||
// Deprecated: This is slower than calling time.Now() directly. | ||
// This is now time.Now().Truncate(time.Second) shortcut. | ||
func CoarseTimeNow() time.Time { | ||
tp := coarseTime.Load().(*time.Time) | ||
return *tp | ||
return time.Now().Truncate(time.Second) | ||
} | ||
|
||
func init() { | ||
t := time.Now().Truncate(time.Second) | ||
coarseTime.Store(&t) | ||
go func() { | ||
for { | ||
time.Sleep(time.Second) | ||
t := time.Now().Truncate(time.Second) | ||
coarseTime.Store(&t) | ||
} | ||
}() | ||
} | ||
|
||
var coarseTime atomic.Value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters