runtime

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2015 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package runtime provides utilities for semaphores (chan struct{}), a simple Latch implementation, and metrics for reporting handled panics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Closer

func Closer(sig chan<- struct{}) func()

return a func that will close the signal chan. multiple invocations of the returned func will not generate a panic. two funcs from separate invocations of Closer() (on the same sig chan) will cause a panic if both invoked. for example:

// good
x := runtime.After(func() { ... })
f := x.Closer()
f()
f()

// bad
x := runtime.After(func() { ... })
f := x.Closer()
g := x.Closer()
f()
g() // this will panic

func Register

func Register()

func Until

func Until(f func(), period time.Duration, stopCh <-chan struct{})

periodically execute the given function, stopping once stopCh is closed. this func blocks until stopCh is closed, it's intended to be run as a goroutine.

Types

type Latch

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

func (*Latch) Acquire

func (self *Latch) Acquire() bool

return true if this latch was successfully acquired. concurrency safe. will only return true upon the first invocation, all subsequent invocations will return false. always returns false when self is nil.

type Signal

type Signal <-chan struct{}

func After

func After(f func()) Signal

spawn a goroutine to execute a func, immediately returns a chan that closes upon completion of the func. returns a nil signal chan if the given func is nil.

func On

func On(sig <-chan struct{}, f func()) Signal

execute a callback function after the specified signal chan closes. immediately returns a signal that indicates f's completion.

func OnOSSignal

func OnOSSignal(sig <-chan os.Signal, f func(os.Signal)) Signal

func (Signal) Then

func (sig Signal) Then(f func()) Signal

upon receiving signal sig invoke function f and immediately return a signal that indicates f's completion. used to chain handler funcs, for example:

On(job.Done(), response.Send).Then(wg.Done)

Jump to

Keyboard shortcuts

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