summaryrefslogtreecommitdiff
path: root/vendor/github.com/puzpuzpuz/xsync/v3/map.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2025-03-03 10:42:05 +0000
committerLibravatar tobi <tobi.smethurst@protonmail.com>2025-03-11 09:42:56 +0100
commit12d4d36bc87326c08c138834f0fd6f86729569be (patch)
tree7b9ad8e2dc70cbcab267336b6b90dbe146f2c35a /vendor/github.com/puzpuzpuz/xsync/v3/map.go
parent[chore]: Bump github.com/ncruces/go-sqlite3 from 0.23.0 to 0.24.0 (#3862) (diff)
downloadgotosocial-12d4d36bc87326c08c138834f0fd6f86729569be.tar.xz
bumps our uptrace/bun dependencies to v1.2.10 (#3865)
Diffstat (limited to 'vendor/github.com/puzpuzpuz/xsync/v3/map.go')
-rw-r--r--vendor/github.com/puzpuzpuz/xsync/v3/map.go41
1 files changed, 21 insertions, 20 deletions
diff --git a/vendor/github.com/puzpuzpuz/xsync/v3/map.go b/vendor/github.com/puzpuzpuz/xsync/v3/map.go
index a2730c3f1..c7837e90b 100644
--- a/vendor/github.com/puzpuzpuz/xsync/v3/map.go
+++ b/vendor/github.com/puzpuzpuz/xsync/v3/map.go
@@ -294,48 +294,49 @@ func (m *Map) LoadAndStore(key string, value interface{}) (actual interface{}, l
)
}
-// LoadOrTryCompute returns the existing value for the key if present.
-// Otherwise, it tries to compute the value using the provided function
-// and, if success, returns the computed value. The loaded result is true
-// if the value was loaded, false if stored. If the compute attempt was
-// cancelled, a nil will be returned.
+// LoadOrCompute returns the existing value for the key if present.
+// Otherwise, it computes the value using the provided function, and
+// then stores and returns the computed value. The loaded result is
+// true if the value was loaded, false if computed.
//
// This call locks a hash table bucket while the compute function
// is executed. It means that modifications on other entries in
// the bucket will be blocked until the valueFn executes. Consider
// this when the function includes long-running operations.
-func (m *Map) LoadOrTryCompute(
- key string,
- valueFn func() (newValue interface{}, cancel bool),
-) (value interface{}, loaded bool) {
+func (m *Map) LoadOrCompute(key string, valueFn func() interface{}) (actual interface{}, loaded bool) {
return m.doCompute(
key,
func(interface{}, bool) (interface{}, bool) {
- nv, c := valueFn()
- if !c {
- return nv, false
- }
- return nil, true
+ return valueFn(), false
},
true,
false,
)
}
-// LoadOrCompute returns the existing value for the key if present.
-// Otherwise, it computes the value using the provided function and
-// returns the computed value. The loaded result is true if the value
-// was loaded, false if stored.
+// LoadOrTryCompute returns the existing value for the key if present.
+// Otherwise, it tries to compute the value using the provided function
+// and, if successful, stores and returns the computed value. The loaded
+// result is true if the value was loaded, or false if computed (whether
+// successfully or not). If the compute attempt was cancelled (due to an
+// error, for example), a nil value will be returned.
//
// This call locks a hash table bucket while the compute function
// is executed. It means that modifications on other entries in
// the bucket will be blocked until the valueFn executes. Consider
// this when the function includes long-running operations.
-func (m *Map) LoadOrCompute(key string, valueFn func() interface{}) (actual interface{}, loaded bool) {
+func (m *Map) LoadOrTryCompute(
+ key string,
+ valueFn func() (newValue interface{}, cancel bool),
+) (value interface{}, loaded bool) {
return m.doCompute(
key,
func(interface{}, bool) (interface{}, bool) {
- return valueFn(), false
+ nv, c := valueFn()
+ if !c {
+ return nv, false
+ }
+ return nil, true
},
true,
false,