Commit graph

3 commits

Author SHA1 Message Date
Boris Nagaev
07c46680e9
fn/ContextGuard: use context.AfterFunc to wait
Simplifies context cancellation handling by using context.AfterFunc instead of a
goroutine to wait for context cancellation. This approach avoids the overhead of
a goroutine during the waiting period.

For ctxQuitUnsafe, since g.quit is closed only in the Quit method (which also
cancels all associated contexts), waiting on context cancellation ensures the
same behavior without unnecessary dependency on g.quit.

Added a test to ensure that the Create method does not launch any goroutines.
2025-01-02 10:38:26 -03:00
Boris Nagaev
865da9c525
fn/ContextGuard: test cancelling blocking context
Make sure WgWait() doesn't block.
2025-01-02 10:38:26 -03:00
Elle Mouton
f99cabf7b4
fn: rework the ContextGuard and add tests
In this commit, the ContextGuard struct is re-worked such that the
context that its new main WithCtx method provides is cancelled in sync
with a parent context being cancelled or with it's quit channel being
cancelled. Tests are added to assert the behaviour. In order for the
close of the quit channel to be consistent with the cancelling of the
derived context, the quit channel _must_ be contained internal to the
ContextGuard so that callers are only able to close the channel via the
exposed Quit method which will then take care to first cancel any
derived context that depend on the quit channel before returning.
2024-12-13 10:44:03 +02:00