Documentation
¶
Overview ¶
Package xcontext is a package to offer the extra functionality we need from contexts that is not available from the standard context package.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Detach ¶
Detach returns a context that keeps all the values of its parent context but detaches from the cancellation and error handling.
Example ¶
package main
import (
"context"
"github.com/komuw/ong/xcontext"
)
type ctxKey string
func log(ctx context.Context, logMsg string) {}
func sendMail(ctx context.Context, msg string) {}
func main() {
key := ctxKey("key")
ctx := context.WithValue(context.Background(), key, "my_value")
// Detach is not required here.
log(ctx, "api called.")
// We need to use Detach here, because sendMail(having been called in a goroutine) can outlive the cancellation of the parent context.
go sendMail(xcontext.Detach(ctx), "hello")
}
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.