Repository navigation
Add xsync.ChangeObservable() and bump minimum Go version to v1.27 - #187
Merged
Merged
Conversation
xsync.StoreIfChanged() and bump minimum Go version to v1.27xsync.ChangeObservable() and bump minimum Go version to v1.27
`StoreIfChanged()` updates an `Observable` only if the new value differs from its current value, so that readers are not woken when nothing has changed. The comparison and the swap are a single atomic step, so it is safe with multiple writers. It is a package-level function rather than a method because it requires the value type to be comparable, which `Observable` itself does not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"Change" carries the "only if different" sense on its own, and the name now says which type it operates on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jmalloc
force-pushed
the
xsync-store-if-changed
branch
from
November 1, 2026 23:53
d12b170 to
9295094
Compare
jmalloc
enabled auto-merge
November 1, 2026 23:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
xsync.ChangeObservable(), which updates anxsync.Observableonly if the new value differs from its current value. Readers are woken only when something actually changed.It reports whether the value was changed. The comparison and the swap happen in the same compare-and-swap loop that
Storeuses, so it's atomic with any number of concurrent writers: two writers can't both see the old value and both report a change. "Change" carries the "only if different" sense on its own, so the name doesn't need an "if changed" suffix.It's a package-level function rather than a method because it needs
Tto be comparable, andObservable[T any]doesn't require that. Go 1.27's method type parameters can't add a constraint to the receiver'sTor tie a method's own type parameter to it, so a method would have to fall back to a runtime type assertion.This PR also bumps the minimum Go version to v1.27.
Motivation
runkit's projection consumer stores whether this node is elected to consume each event stream, and each stream's worker restarts consumption when that value changes. Storing an unchanged value wakes the worker for nothing. Comparing before storing outside
xsyncisn't atomic, so this belongs here.Testing
x/xsynchas tests for changing the value, skipping an unchanged one, treating the zero value as the initial value, and concurrent writers. The concurrent test checks that the final boolean matches the parity of the calls that reported a change. It fails against a non-atomic load-compare-store.🤖 Generated with Claude Code