ctx

package module
v0.0.0-...-0bfd988 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2018 License: MIT Imports: 3 Imported by: 8

README

ctx

Composable utilities for Go contexts.

Godoc Reference Go Report Card

Installation

go get -u github.com/SentimensRG/ctx

Overview

The ctx package provides utilites for working with data structures satisfying the ctx.Doner interface, most notably context.Context:

type Doner interface {
    Done() <-chan struct{}
}

The functions in ctx are appropriate for operations that do not preserve the values in a context, e.g.: joining several contexts together.

Subpackages

  • sigctx: contexts for graceful shutdown
  • refctx: contexts linked to a reference-counter
  • mergectx: utilities for merging context.Context instances while preserving values, errors and deadlines.

RFC

If you find this useful please let me know: l.thibault@sentimens.com

Seriously, even if you just used it in your weekend project, I'd like to hear about it :)

License

The MIT License

Copyright (c) 2017 Sentimens Research Group, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsContext

func AsContext(d Doner) context.Context

AsContext creates a context that fires when the Doner fires

func Defer

func Defer(d Doner, cb func())

Defer guarantees that a function will be called after a context has cancelled

func FTick

func FTick(d Doner, f func())

FTick calls a function in a loop until the Doner has fired

func FTickInterval

func FTickInterval(d Doner, t time.Duration, f func())

FTickInterval calls a function repeatedly at a given internval, until the Doner has fired. Note that FTickInterval ignores the time spent executing a function, and instead guarantees an interval of `t` between of return of the previous function call and the invocation of the next function call.

func Tick

func Tick(d Doner) <-chan struct{}

Tick returns a <-chan whose range ends when the underlying context cancels

Types

type BindFunc

type BindFunc func(Doner)

BindFunc is an adapter to allow the use of ordinary functions as Binders.

func (BindFunc) Bind

func (f BindFunc) Bind(d Doner)

Bind executes logic until the Doner completes. It satisfies the Binder interface.

type Binder

type Binder interface {
	Bind(Doner)
}

Binder is the interface that wraps the basic Bind method. Bind executes logic until the Doner completes. Implementations of Bind must not return until the Doner has completed.

type C

type C <-chan struct{}

C is a basic implementation of Doner

func After

func After(d time.Duration) C

After time time has elapsed, the Doner fires

func Background

func Background() C

Background is the ctx analog to context.Background(). It never fires.

func FDone

func FDone(f func()) C

FDone returns a doner that fires when the function returns or panics

func Join

func Join(doners ...Doner) C

Join returns a channel that receives when all constituent Doners have fired

func Link(doners ...Doner) C

Link returns a channel that fires if ANY of the constituent Doners have fired

func WithCancel

func WithCancel(d Doner) (C, func())

WithCancel returns a new Doner that can be cancelled via the associated function

func (C) Done

func (dc C) Done() <-chan struct{}

Done returns a channel that receives when an action is complete

type Doner

type Doner interface {
	Done() <-chan struct{}
}

Doner can block until something is done

Directories

Path Synopsis
Package mergectx provides a utility for merging two context.Context objects, creating a child context that contains the union of both context's values.
Package mergectx provides a utility for merging two context.Context objects, creating a child context that contains the union of both context's values.
Package refctx provides a context tied to a reference-counter.
Package refctx provides a context tied to a reference-counter.
Package sigctx provides a context that expires when a SIGINT or SIGTERM is received.
Package sigctx provides a context that expires when a SIGINT or SIGTERM is received.

Jump to

Keyboard shortcuts

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