fscontext

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package fscontext contains helpers for migrating Fleetspeak to context.Context.

Fleetspeak should better use context.Context for cancelation than chan struct{}s.

Index

Constants

This section is empty.

Variables

View Source
var ErrStopRequested = fmt.Errorf("%w: stop requested", context.Canceled)

ErrStopRequested is the cancelation cause to be used when callers intentionally cancel a context from the outside.

Functions

func WithDoneChan

func WithDoneChan(ctx context.Context, cause error, done <-chan struct{}) (newCtx context.Context, cancel context.CancelCauseFunc)

WithDoneChan returns a new context and cancel function.

The context is automatically canceled with the given cause as soon as done is closed.

This is not meant as a long-term solution, but as a migration path for code which has a "done" channel but which needs to provide a context.

Callers must always call cancel after the context is done.

Example usage:

 errDoneClosed := fmt.Errorf("my magic done channel was closed: %w", fscontext.ErrStopRequested)
	ctx, cancel := fscontext.WithDoneChan(ctx, errDoneClosed, xyz.done)
	defer cancel(nil)

Types

This section is empty.

Jump to

Keyboard shortcuts

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