context

package
v0.1.292 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

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.

https://developer.squareup.com/blog/always-be-closing/

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL