xcontext

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package xcontext provides utilities for working with contexts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Stopped

func Stopped(ctx context.Context) <-chan struct{}

Stopped returns a channel that is closed when the context is stopped.

It returns nil if the context is not stoppable.

Types

type StopFunc

type StopFunc func()

A StopFunc tells an operation to stop after its completed its current unit of work. It is used to implement graceful shutdown semantics.

Contrast to context.CancelFunc which is is typically used to implement "forceful" cancellation semantics.

It does not wait for the work to stop. It may be called by multiple goroutines simultaneously. After the first call, subsequent calls do nothing.

func WithStop

func WithStop(parent context.Context) (ctx context.Context, stop StopFunc)

WithStop returns a derived context that points to the parent context but has a new Stopped channel.

The returned context's Stopped channel is closed when the returned stop function is called or when the parent context's Stopped channel is closed, whichever happens first.

Canceling the parent context not close the returned context's Stopped channel.

Jump to

Keyboard shortcuts

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