summaryrefslogtreecommitdiff
path: root/typedsync/map.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-02-05 13:02:57 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-05 13:33:02 -0700
commit5a1a904b4264c6ee323c9bd433f9ee4da93c984d (patch)
tree035414c8e8f3b94e24b482e5096a3b4e3688e257 /typedsync/map.go
parent2d939c9c6e62395ed924fe7c5cd4c4b294e391a9 (diff)
typedsync: Bring up to being a mostly-drop-in replacement for Go 1.20 sync
Diffstat (limited to 'typedsync/map.go')
-rw-r--r--typedsync/map.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/typedsync/map.go b/typedsync/map.go
index 6bb1170..2f94ae2 100644
--- a/typedsync/map.go
+++ b/typedsync/map.go
@@ -10,20 +10,33 @@ import (
// Map is a type-safe equivalent of the standard library's sync.Map.
//
-// With versions of Go prior to Go 1.20, Map is specified too loosely,
-// as
+// See the [sync.Map documentation] for full details.
+//
+// Go 1.20 added sync.Map.Swap method; this method is only available
+// on typedsync.Map if built with Go 1.20 or later.
+//
+// Go 1.20 added sync.Map.CompareAndDelete and sync.Map.CompareAndSwap
+// methods that are only usable if V is a comparable type; these
+// methods are not available on typedsync.Map, but when typedsync is
+// built with Go 1.20 or later they are available on a separate
+// ComparableMap type.
+//
+// When typedsync is built versions of Go prior to Go 1.20,
+// typedsync.Map is specified too loosely, as
//
// Map[K any, V any]
//
-// while with Go 1.20 and later, Map is specified as
+// while with Go 1.20 and later, typedsync.Map is specified as
//
// Map[K comparable, V any]
//
// This is because with Go versions prior to 1.20, 'comparable' was
// overly strict, disallowing many types that are valid map-keys (see
// https://github.com/golang/go/issues/56548). The type used as K in
-// a Map older versions of Go must be a valid map-key type, even
+// a Map with older versions of Go must be a valid map-key type, even
// though the type specification of Map does not enforce that.
+//
+// [sync.Map documentation]: https://pkg.go.dev/sync#Map
type Map[K mapkey, V any] struct {
inner sync.Map
}