barrier

package module
v0.0.0-...-01ce0af Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2016 License: BSD-3-Clause Imports: 1 Imported by: 2

README

Barrier

DEPRECATED - You probably want the standard library context instead, which can be used to achieve the same effect with cancellation.

Documentation: http://godoc.org/github.com/pwaller/barrier

golang-nuts mailing list discussion

Documentation

Overview

A barrier primitive which can be used to signal a permanent state change, for example to signal that shutdown should occur.

golang-nuts mailing list discussion: https://groups.google.com/d/topic/golang-nuts/RBQjg6YOiWA/discussion

Example:

package main

import (
	"sync"

	"github.com/pwaller/barrier"
)

func main() {
	var w sync.WaitGroup
	defer w.Wait() // Main should wait for its goroutines

	var b barrier.Barrier

	w.Add(1)
	go func() {
		defer w.Done()
		defer b.Fall()
		println("GO!")
		<-b.Barrier() // Many goroutines can wait on the barrier
	}()

	w.Add(1)
	go func() {
		defer w.Done()
		defer b.Fall()
		println("GO!")
		// When this goroutine happens to return,
		// all barrier waits can be passed.
		return
	}()

}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Barrier

type Barrier struct {

	// An optional hook, which if set, is called exactly once when the first
	// b.Fall() is invoked.
	FallHook func()
	// contains filtered or unexported fields
}

The zero of Barrier is a ready-to-use value

func (*Barrier) Barrier

func (b *Barrier) Barrier() <-chan struct{}

When `b.Fall()` is called, the channel returned by Barrier() is closed (and becomes always readable)

func (*Barrier) Fall

func (b *Barrier) Fall()

`b.Fall()` can be called any number of times and causes the channel returned by `b.Barrier()` to become closed (permanently available for immediate reading)

func (*Barrier) Forward

func (b *Barrier) Forward(f *Barrier)

Forward will cause `f.Fall()` to be invoked if `b.Fall()` is invoked. The implementation ensures that any reference `b` holds to `f` is removed if `f` falls.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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