Debian Codegraph @

time.go

raw symbols SCIP
1 package utilsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/
2
3 import (
4 "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/"
5 "sync/atomicscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/"
6 "timescip-go gomod github.com/golang/go/src go1.25.0 time/"
7 )
8
9 var (
10 timestampscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/timestamp. atomicscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/.Uint32scip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/Uint32#
11 updaterMuscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/updaterMu. syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Mutexscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#
12 stopUpdaterscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/stopUpdater. chan struct{}
13 updaterDonescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/updaterDone. chan struct{}
14 )
15
16 // Timestamp returns the current cached Unix timestamp (seconds).
17 // Call StartTimeStampUpdater() once at app startup for best performance.
18 func Timestampscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Timestamp().() uint32 {
19 return timestampscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/timestamp..Loadscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/Uint32#Load().()
20 }
21
22 // StartTimeStampUpdater launches a background goroutine that updates the cached timestamp every second.
23 // It is safe to call multiple times and from multiple goroutines; only one updater runs at a time.
24 func StartTimeStampUpdaterscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/StartTimeStampUpdater().() {
25 updaterMuscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/updaterMu..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().()
26 defer updaterMuscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/updaterMu..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Unlock().()
27 if stopUpdaterscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/stopUpdater. != nil {
28 return
29 }
30
31 timestampscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/timestamp..Storescip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/Uint32#Store().(uint32(timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().().Unixscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Unix().()))
32 stopUpdaterscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/stopUpdater. = make(chan struct{})
33 updaterDonescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/updaterDone. = make(chan struct{})
34
35 go func(stop, done chan struct{}) {
36 ticker := timescip-go gomod github.com/golang/go/src go1.25.0 time/.NewTickerscip-go gomod github.com/golang/go/src go1.25.0 time/NewTicker().(timescip-go gomod github.com/golang/go/src go1.25.0 time/.Secondscip-go gomod github.com/golang/go/src go1.25.0 time/Second.)
37 defer ticker.Stopscip-go gomod github.com/golang/go/src go1.25.0 time/Ticker#Stop().()
38 defer close(done)
39
40 for {
41 select {
42 case <-ticker.Cscip-go gomod github.com/golang/go/src go1.25.0 time/Ticker#C.:
43 timestampscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/timestamp..Storescip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/Uint32#Store().(uint32(timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().().Unixscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Unix().()))
44 case <-stop:
45 return
46 }
47 }
48 }(stopUpdaterscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/stopUpdater., updaterDonescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/updaterDone.)
49 }
50
51 // StopTimeStampUpdater stops the background updater goroutine.
52 // Call this on app shutdown to avoid leaking goroutines.
53 // It is safe to call multiple times and from multiple goroutines.
54 func StopTimeStampUpdaterscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/StopTimeStampUpdater().() {
55 updaterMuscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/updaterMu..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().()
56 defer updaterMuscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/updaterMu..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Unlock().()
57 if stopUpdaterscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/stopUpdater. == nil {
58 return
59 }
60
61 close(stopUpdaterscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/stopUpdater.)
62 <-updaterDonescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/updaterDone.
63 stopUpdaterscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/stopUpdater. = nil
64 updaterDonescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/updaterDone. = nil
65 }