Lock() in sync.Mutex / sync.RWMutex vs RLock() in sync.RWMutex:
Lock() — blocks readers AND writers
RLock() — blocks writers only, does NOT block other readers
Use RWMutex RLock() when reads >> writes.
#golang #concurrency
Lock() in sync.Mutex / sync.RWMutex vs RLock() in sync.RWMutex:
Lock() — blocks readers AND writers
RLock() — blocks writers only, does NOT block other readers
Use RWMutex RLock() when reads >> writes.
#golang #concurrency
sync.Once's .Do and sync.OnceFunc both take func() — no return.
So the result has to live somewhere: a separate struct field you write to as a side effect.
sync.OnceValue takes func() T — the return value IS the cache. No extra field.
#golang #concurrency
time.After(d): Concurrency tool. Sets up a background timer and returns a channel.
t.After(u): Date/time method. Instant boolean comparison to check if timestamp t occurs after timestamp u.
#Golang time package
Go proverb: “errors are values” means “errors are values that implement the `error` interface.”
Release notes are up!
I wish it went without saying, but these notes are completely written by hand.
Go's time package has two sides:
date/time handling
Timer-based concurrency tools:
time.NewTimer(d)
timer.Stop()
timer.Reset(d)
time.After(d)
time.AfterFunc(d, f)
time.NewTicker(d)
ticker.Stop()
time.Tick(d)