aboutsummaryrefslogtreecommitdiffstats
path: root/internal/tag
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2026-03-11 10:24:30 -0400
committerSam Anthony <sam@samanthony.xyz>2026-03-11 10:24:30 -0400
commit21732d319a2dfd061d798f3e5bfa6fdacc28be38 (patch)
tree89aa30991cb613f9fcf44e4598f9f09db39b49f2 /internal/tag
parent9a2c345cfd3697a5de3f5fd799f682ab822e3756 (diff)
downloadgui-21732d319a2dfd061d798f3e5bfa6fdacc28be38.zip
lay/strain: replace Solver mutex with channels
Partially reverts 483236742ddcd7883b5f9cff92244129274aa79c. Solver still closes itself automatically, but reverted to using request/reply channels. Mutex was becoming annoying to manage, as expected. TODO: TestRows fails intermittently due to constraint channels not being flushed when Solve() is called.
Diffstat (limited to 'internal/tag')
-rw-r--r--internal/tag/tag.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/internal/tag/tag.go b/internal/tag/tag.go
index 197d2d6..b4b627d 100644
--- a/internal/tag/tag.go
+++ b/internal/tag/tag.go
@@ -1,12 +1,22 @@
package tag
+import "context"
+
type Tagged[V, T any] struct {
Val V
Tag T
}
-func Tag[V, T any](out chan<- Tagged[V, T], in <-chan V, f func(V) T) {
- for val := range in {
- out <- Tagged[V, T]{val, f(val)}
+func Tag[V, T any](ctx context.Context, out chan<- Tagged[V, T], in <-chan V, f func(V) T) {
+ for {
+ select {
+ case val, ok := <-in:
+ if !ok {
+ return
+ }
+ out <- Tagged[V, T]{val, f(val)}
+ case <-ctx.Done():
+ return
+ }
}
}