stopcontext

package
v0.0.0-...-1e697c3 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package stopcontext extentds the standard Context interface with an additional Stopped signal, intended for gracefully stopping some iterative process associated with the Context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Stopped

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

Stopped is a helper function that calls Stopped if the given context has an ancestor created with WithStop from this package and Done otherwise.

It is useful for iterative processes that want to support both the standard Context and the graceful stop provided by this package's Context.

func WithStop

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

WithStop derives a Context whose Stopped signal is triggered by calling the returned StopFunc.

If the parent context has an ancestor created with WithStop, the new Context's Stopped signal will propagate the parent's Stopped signal too.

Types

type Context

type Context interface {
	context.Context

	// Stopped works similarly to Done, except it's also triggered by a call to
	// a StopFunc returned by WithStop.
	Stopped() <-chan struct{}
	// contains filtered or unexported methods
}

Context wraps a context.Context. In addition to inheriting the wrapped context's Done signal, it has an additional Stopped signal that signals that some iterative process associated with the Context should stop on the next iteration, in a graceful manner.

Context cancellation also triggers the Stopped signal, so you don't need to attend to both.

type StopFunc

type StopFunc = func()

A StopFunc is like a context.CancelFunc, except it triggers a Stopped signal.

Jump to

Keyboard shortcuts

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