context

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Overview

Copyright 2023 The acquirecloud Authors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package context adds some utility functions to work with the standard context.Context objects:

  • NewSignalsContext(): creates a context that will be closed when one of some specified system signals are sent to the program
  • Sleep(): the goroutine sleeping with the context functionality (the goroutine sleep will be interrupted if the provided context is closed)
  • WrapChannel(): the function allows to wrap of a channel and creates a context object, which will be closed if the channel is closed.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSignalsContext

func NewSignalsContext(signals ...os.Signal) context.Context

NewSignalsContext returns a context.Context that will be closed by one of the provided syscall.Signal(s)

func Sleep

func Sleep(ctx context.Context, d time.Duration) error

Sleep allows to sleep for duration of until the ctx is closed. Will return ctx.Err() or nil

func WrapChannel

func WrapChannel(ch <-chan struct{}) ctx.Context

WrapChannel receives a channel and returns a context which wraps the channel The context will be closed when the channel is closed.

Types

type CancelErrFunc

type CancelErrFunc func(err error)

func WithCancelError

func WithCancelError(parent ctx.Context) (ctx.Context, CancelErrFunc)

WithCancelError allows creating a context with cancel custom error. The CancelErrFunc must be always called when the context is not used anymore

Jump to

Keyboard shortcuts

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