add working signup + login
This commit is contained in:
parent
bc85b7c340
commit
d8cb8c8fa8
27 changed files with 600 additions and 39 deletions
30
internal/concurrent/value.go
Normal file
30
internal/concurrent/value.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package concurrent
|
||||
|
||||
import "sync"
|
||||
|
||||
// Value is a struct providing concurrent access to another type.
|
||||
// Note: T should be a concrete type, not a pointer.
|
||||
type Value[T any] struct {
|
||||
val T
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
func NewValue[T any](value T) *Value[T] {
|
||||
return &Value[T]{
|
||||
val: value,
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Value[T]) Get() T {
|
||||
v.mu.RLock()
|
||||
val := v.val
|
||||
v.mu.RUnlock()
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
func (v *Value[T]) Set(new T) {
|
||||
v.mu.Lock()
|
||||
v.val = new
|
||||
v.mu.Unlock()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue