Documentation
¶
Index ¶
- Variables
- type Map
- func (p *Map[K, V]) Delete(key K)
- func (p *Map[K, V]) Load(key K) (V, bool)
- func (p *Map[K, V]) LoadAndDelete(key K) (V, bool)
- func (p *Map[K, V]) LoadOrCreate(key K, create func() V) (V, bool)
- func (p *Map[K, V]) LoadOrStore(key K, value V) (V, bool)
- func (p *Map[K, V]) Range(call func(key K, value V) bool)
- func (p *Map[K, V]) Store(key K, value V)
- type RoutineGroup
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrSizeLessZero = errors.New("size less than 0")
Functions ¶
This section is empty.
Types ¶
type Map ¶ added in v1.0.40
type Map[K comparable, V any] struct{ sync.Map }
func NewMap ¶ added in v1.0.40
func NewMap[K comparable, V any](items ...lo.Tuple2[K, V]) *Map[K, V]
Example ¶
package main
import (
"fmt"
"github.com/xuender/kit/sync"
)
func main() {
smap := sync.NewMap[int, int]()
smap.Store(1, 1)
fmt.Println(smap.Load(1))
fmt.Println(smap.LoadOrCreate(2, func() int { return 2 }))
}
Output: 1 true 2 false
func (*Map[K, V]) LoadAndDelete ¶ added in v1.0.40
func (*Map[K, V]) LoadOrCreate ¶ added in v1.0.40
func (*Map[K, V]) LoadOrStore ¶ added in v1.0.40
type RoutineGroup ¶
type RoutineGroup struct {
// contains filtered or unexported fields
}
RoutineGroup 协程组,是sync.WaitGroup的增强版本.
func NewRoutineGroup ¶
func NewRoutineGroup(size int32) *RoutineGroup
NewRoutineGroup 协程组,控制协程总数量.
Example ¶
package main
import (
"fmt"
"github.com/xuender/kit/sync"
)
func main() {
group := sync.NewRoutineGroup(3)
for range 5 {
group.Incr()
go func() {
defer group.Done()
fmt.Println("x")
}()
}
group.Wait()
}
Output: x x x x x
func (*RoutineGroup) Incr ¶ added in v1.0.46
func (p *RoutineGroup) Incr()
Incr 加1.
Example ¶
package main
import (
"fmt"
"github.com/xuender/kit/sync"
)
func main() {
group := sync.NewRoutineGroup(3)
for range 5 {
group.Incr()
go func() {
defer group.Done()
fmt.Println("x")
}()
}
group.Wait()
}
Output: x x x x x
Click to show internal directories.
Click to hide internal directories.