waiter

package module
v0.0.0-...-dda96d2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2013 License: MIT Imports: 4 Imported by: 4

README

waiter Build Status

A simple way to join return-less concurrently executing goroutines.

Documentation

Documentation

Install

go get github.com/yanatan16/gowaiter

Use

import (
  "github.com/yanatan16/gowaiter"
)

func DoThreeThingsInParallel() error {
  w := waiter.New(3)

  go func () {
    if err := Something(); err != nil {
      w.Errors <- err
    }
    if err := Something2(): err != nil {
      w.Errors <- err
    }
    w.Done <- true
  }()

  go func () {
    // For simple functions, we can use a simpler syntax
    w.Wrap(DoSomethingElse())
  }()

  // For closing a type, theres even simpler syntax
  closer := CloserType(true)
  w.Close(closer)

  // Returns first error or nil after 3 Done's.
  return w.Wait()
}

type CloserType bool
func (t CloserType) Close() error {...}

func DoSomethingElse() error {...}

License

MIT License found in LICENSE file.

Documentation

Overview

Package waiter provides a nice way to perform return-less parallel operations

Example:

func DoThreeThingsParallel() error {
  w := waiter.New(3)

  go func () {
    // do something
    if err != nil {
      w.Errors <- err
    }
    // done
    w.Done <- true
  }()

  go func () {
    err := doSomethingElse()
    w.Wrap(err) // Takes care of errors and done channels
  }()

  w.Close(CloserInterface)

  return w.wait()
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Waiter

type Waiter struct {
	Errors chan error
	Done   chan bool
	Count  int
}

func New

func New(cnt int) *Waiter

func (*Waiter) Bypass

func (w *Waiter) Bypass()

Bypass a single wait. That is, we decrement count.

func (Waiter) Close

func (w Waiter) Close(closer io.Closer)

func (Waiter) Wait

func (w Waiter) Wait() error

func (Waiter) WaitTimeout

func (w Waiter) WaitTimeout(timeout time.Duration) error

func (Waiter) Wrap

func (w Waiter) Wrap(err error)

Jump to

Keyboard shortcuts

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