Skip to content

Commit 61335f5

Browse files
committed
moved for loop on onClose func into closeOnce
1 parent 70b6863 commit 61335f5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

internal/query/result.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ func newResult(
139139

140140
r.closeOnce = sync.OnceFunc(func() {
141141
close(closed)
142+
143+
for i := range r.onClose {
144+
r.onClose[len(r.onClose)-i-1]()
145+
}
142146
})
143147

144148
if r.trace != nil {
@@ -231,13 +235,7 @@ func (r *streamResult) Close(ctx context.Context) (finalErr error) {
231235
}()
232236
}
233237

234-
defer func() {
235-
r.closeOnce()
236-
237-
for i := range r.onClose {
238-
r.onClose[len(r.onClose)-i-1]()
239-
}
240-
}()
238+
defer r.closeOnce()
241239

242240
for {
243241
select {

0 commit comments

Comments
 (0)