chanUtils

package module
v0.0.0-...-052ab62 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2017 License: MIT Imports: 2 Imported by: 2

README

What's this?

  • ChanUtils is a utility library for goroutins and channels in Go
  • Channels and goroutines are very useful, but some utilities are necessary to use them comfortably.

Classes

  • ExitedNotifier
    • When you call Finish(), all waiting goroutines will be resumed.
  • SimpleTrigger
    • This can wakes up one waiting goroutine many times.
    • The number that Wait() or <-trigger is called is NOT insured.
  • Trigger
    • This can wakes up one waiting goroutine many times.
    • The number that Wait() or WaitWithContext() is called is insured.

License

  • Under the MIT License
  • Copyright (c) 2017 Tsuzu

Examples

  • Not prepared yet.
  • Please refer to *_test.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExitedNotifier

type ExitedNotifier struct {
	Channel chan bool
	// contains filtered or unexported fields
}

ExitedNotifier When you call Finish(), all waiting goroutines will be resumed.

func NewExitedNotifier

func NewExitedNotifier() *ExitedNotifier

NewExitedNotifier creates a new ExitedNotifier

func (*ExitedNotifier) Finish

func (en *ExitedNotifier) Finish()

Finish resumes all waiting goroutines

func (*ExitedNotifier) TriggerOrCancel

func (en *ExitedNotifier) TriggerOrCancel(f func()) func()

TriggerOrCancel sets f() to be called when Finish() is called. The returned function is a canceller. Note that you must call this when you no longer need f() to be called.

func (*ExitedNotifier) Wait

func (en *ExitedNotifier) Wait()

Wait waits Finish() is called.

func (*ExitedNotifier) WaitWithContext

func (en *ExitedNotifier) WaitWithContext(ctx context.Context)

WaitWithContext waits until Finish() is called or ctx is triggered.

type SimpleTrigger

type SimpleTrigger chan bool

SimpleTrigger wakes up one waiting goroutine many times. The number that Wait() or <-trigger is called is NOT insured. Note that Wait() or <-trigger can be used by only one goroutine.

func NewSimpleTrigger

func NewSimpleTrigger() SimpleTrigger

NewSimpleTrigger creates a new Trigger

func (SimpleTrigger) Wait

func (trigger SimpleTrigger) Wait()

Wait waits until Wake() is called.

func (SimpleTrigger) WaitWithContext

func (trigger SimpleTrigger) WaitWithContext(ctx context.Context) error

WaitWithContext waits until Wake() or ctx.Done()

func (SimpleTrigger) Wake

func (trigger SimpleTrigger) Wake()

Wake resume a goroutine calling Wait()

type Trigger

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

Trigger wakes up a waiting goroutine many times. The number that Wait() or WaitWithContext() is called is insured. Note that Wait() or <-trigger can be used by only one goroutine.

func NewTrigger

func NewTrigger() *Trigger

NewTrigger creates a new Trigger

func (*Trigger) Wait

func (trigger *Trigger) Wait()

Wait waits until Wake() is called.

func (*Trigger) WaitWithContext

func (trigger *Trigger) WaitWithContext(ctx context.Context) error

WaitWithContext waits until trigger.Wake() or ctx.Done()

func (*Trigger) Wake

func (trigger *Trigger) Wake()

Wake resume a goroutine calling Wait()

Jump to

Keyboard shortcuts

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