File: xsync_go1.21.go

package info (click to toggle)
golang-github-bradenaw-juniper 0.15.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 872 kB
  • sloc: sh: 27; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 716 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//go:build go1.21

package xsync

import (
	"sync"
)

// Lazy makes a lazily-initialized value. On first access, it uses f to create the value. Later
// accesses all receive the same value.
//
// Deprecated: sync.OnceValue is in the standard library as of Go 1.21.
func Lazy[T any](f func() T) func() T {
	return sync.OnceValue(f)
}

func (m *Map[K, V]) CompareAndDelete(key K, old V) (deleted bool) {
	return m.m.CompareAndDelete(key, old)
}
func (m *Map[K, V]) CompareAndSwap(key K, old V, new V) (deleted bool) {
	return m.m.CompareAndSwap(key, old, new)
}
func (m *Map[K, V]) Swap(key K, value V) (previous V, loaded bool) {
	previousUntyped, loaded := m.m.Swap(key, value)
	return previousUntyped.(V), loaded
}