util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanSelect

func CanSelect(ch <-chan struct{}) bool

CanSelect is a helper for struct{} channels that checks if the channel can be pulled from in a select statement. It is recommended to use this only for channels whose purpose is signaling (i.e. closing the given channel when something is done, at which point it can always be selected, rather than transmitting actual struct{} values), since using this with actual struct{} values would cause a value to get pulled off the channel and potentially mess up synchronization.

func CommonGRPC

func CommonGRPC() []grpc.DialOption

CommonGRPC returns a set of commonly used GRPC dial options for Anki's cloud services, if any are defined for the current platform.

func NewChanWriter

func NewChanWriter(ch chan<- []byte) io.Writer

NewChanWriter returns a wrapper around a []byte channel that turns it into an io.Writer

func SleepSelect

func SleepSelect(dur time.Duration, ch <-chan struct{}) bool

SleepSelect is like calling time.Sleep() with an early exit if the given channel ch is closed. It can be used for situations such as a goroutine wanting to sleep while still responding quickly if it receives a signal from a channel. Returns true if sleep was ended early due to selecting from the channel, false if the sleep completed.

func TimeFuncMs

func TimeFuncMs(function func()) float64

TimeFuncMs returns the time, in milliseconds, required to run the given function

Types

type DoOnce

type DoOnce struct {
	// contains filtered or unexported fields
}

DoOnce wraps a sync.Once object, taking a function at initialization time rather than at execution time; that way, if the function to be executed is known in advance for all cases, it can be stored in the object rather than repeated in arguments to Once.Do()

func NewDoOnce

func NewDoOnce(todo func()) DoOnce

NewDoOnce returns a new DoOnce object that will store the given function and execute it in calls to DoOnce.Do()

func (*DoOnce) Do

func (d *DoOnce) Do()

Do executes the function associated with this DoOnce instance

type ErrorListener

type ErrorListener interface {
	OnError(error)
}

ErrorListener defines an interface that can be used as a common definition to inject error handlers into dependent modules

type Errors

type Errors struct {
	// contains filtered or unexported fields
}

func NewErrors

func NewErrors(errs ...error) *Errors

func (*Errors) Append

func (e *Errors) Append(err error)

func (*Errors) AppendMulti

func (e *Errors) AppendMulti(errs ...error)

func (*Errors) Error

func (e *Errors) Error() error

type MapCredentials

type MapCredentials map[string]string

func AppkeyMetadata

func AppkeyMetadata() MapCredentials

func (MapCredentials) GetRequestMetadata

func (r MapCredentials) GetRequestMetadata(context.Context, ...string) (map[string]string, error)

func (MapCredentials) RequireTransportSecurity

func (r MapCredentials) RequireTransportSecurity() bool

Jump to

Keyboard shortcuts

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