Documentation ¶
Overview ¶
There be a memory leak when calling WithTimeout and you don't call the cancel func. Its really easy to forget to put the defer cancel() after the WithTimeout call.
Its easy to seach our code base for anyone calling WithTimeout and replacing it with NewContextWithTimeout.
Here we ensure that the cancel func is called when the request pipeline is complete.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewContextWithTimeout ¶
func NewContextWithTimeout(ctx context.Context, duration time.Duration) (context.Context, context.CancelFunc)
NewContextWithTimeout creates a new context with a timeout
func SetContextWithTimeoutManager ¶
func SetContextWithTimeoutManager(ctx context.Context, contextWithTimeoutManager *WithTimeoutManager) context.Context
SetContextWithTimeoutManager adds the ContextWithTimeoutManager to the context
Types ¶
type WithTimeoutManager ¶
type WithTimeoutManager struct {
// contains filtered or unexported fields
}
WithTimeoutManager manages cancel funcs
func NewContextWithTimeoutManager ¶
func NewContextWithTimeoutManager() *WithTimeoutManager
NewContextWithTimeoutManager creates a new ContextWithTimeoutManager
func (*WithTimeoutManager) CancelAll ¶
func (c *WithTimeoutManager) CancelAll()
CancelAll cancels all the cancel funcs
Click to show internal directories.
Click to hide internal directories.