Skip to content

Commit

Permalink
Add ability to pass in a mergewith to opset
Browse files Browse the repository at this point in the history
  • Loading branch information
ajroetker committed Oct 16, 2024
1 parent d175fff commit 03fb736
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion opqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewOpQueue(depth, width int) *OpQueue {
entries: map[ID]*OpSet{},

reducer: func(opset *OpSet, op *Op) {
opset.append(op)
opset.MergeWith(append, op)

Check failure on line 52 in opqueue.go

View workflow job for this annotation

GitHub Actions / Go 1.x.x (ubuntu-latest)

append (built-in) must be called
},
}
q.cond.L = &q.mu
Expand Down
7 changes: 5 additions & 2 deletions opset.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ func newOpSet(op *Op) *OpSet {
}
}

func (os *OpSet) append(op *Op) {
os.set = append(os.set, op)
func appendOp(ops []*Op, op *Op) []*Op {
return append(ops, op)
}
func (os *OpSet) MergeWith(fn func([]*Op, *Op) []*Op, op *Op) {
os.set = fn(os.set, op)
}

// Ops get the list of ops in this set.
Expand Down
2 changes: 1 addition & 1 deletion opwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewOpWindow(depth, width int, windowedBy time.Duration) *OpWindow {
windowedBy: windowedBy,
m: make(map[ID]*queueItem),
reducer: func(opset *OpSet, op *Op) {
opset.append(op)
opset.MergeWith(appendOp, op)
},
}
q.q.Init()
Expand Down

0 comments on commit 03fb736

Please sign in to comment.