Skip to content

Commit

Permalink
cancel hook fn & add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobOaks committed May 29, 2024
1 parent a0a2fcd commit 1c5db75
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fxtest/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ func (l *Lifecycle) withTimeout(ctx context.Context, fn func(context.Context) er
return fn(ctx)
}

c := make(chan error, 1)
// Cancel on timeout in case function only respects
// cancellation and not deadline exceeded.
ctx, cancel := context.WithCancel(ctx)
defer cancel()

c := make(chan error, 1) // buffered to avoid goroutine leak
go func() {
c <- fn(ctx)
}()
Expand Down

0 comments on commit 1c5db75

Please sign in to comment.