context

package
v0.0.0-...-fee7787 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Detach

func Detach(ctx context.Context) context.Context

Detach creates a detached context (without cancel and deadline) from a parent ctx. Example:

import myapp/context
func home(w http.ResponseWriter, r *http.Request) {
	log.Println("home")
	// Create a Detached context
	detachedCtx := context.Detach(r.Context())
	detachedDeadline, ok := detachedCtx.Deadline()
	fmt.Println("DETACHED ---")
	fmt.Println("Deadline():", detachedDeadline, ok) // 0001-01-01 00:00:00 +0000 UTC false
	fmt.Println("Err():", r.Context().Err()) // <empty>
	backgroundTask.Run(detachedCtx) // prevents task stop when r.Context has cancelled
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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