Closed favonia closed 8 months ago
Done in commit 578a11a744c37bd19c1c1b8d96061276dbf6f7f0.
@junyer Thanks for your quick response. Out of curiosity, is there a reason to use sync.Once
instead of a simple global variable (and init
)?
sync.OnceValue()
became available as of Go 1.21 only three months ago, admittedly, but it feels neater than setting a global variable via an init()
function.
@junyer I checked the sync
package and felt the overhead is quite large---there are mutexes to deal with multithreading and complicated control flows to optimize stack traces. None of these features are useful here. Personally I would suggest using simple boolean values, but I guess it does not hurt much and you are the maintainer. 😅
It isn't a hot code path, so what's happening under the hood doesn't hurt at all. It matters more to have clearer, simpler code: the use of sync.OnceValue()
concisely signals that isXDG
is a func() bool
whose return value is memoised.
Completely close #20.
Tagging @jasonkarns in case they have anything to say.