Skip to content

Commit

Permalink
fn/ContextGuard: clear store of cancel funcs
Browse files Browse the repository at this point in the history
If ContextGuard lives for some time after Quit method is called, the map won't
be collected by GC. Optimization.
  • Loading branch information
starius committed Dec 14, 2024
1 parent 5594283 commit 1f042cd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fn/context_guard.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (g *ContextGuard) Quit() {
cancel()
}

// Clear cancelFns. It is safe to use nil, because no write
// operations to it can happen after g.quit is closed.
g.cancelFns = nil

close(g.quit)
})
}
Expand Down

0 comments on commit 1f042cd

Please sign in to comment.