channels

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: Apache-2.0 Imports: 3 Imported by: 11

README

channels

Helper library to simplify use of Go channels

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Awaitable

type Awaitable interface {
	After(timeout time.Duration) Awaitable
	Channel() <-chan Void
	Next(action func()) Awaitable
	Peek() bool
	Wait(timeout time.Duration) bool
	WaitForever()
	WaitTimer(timerC <-chan time.Time) bool
}

Awaitable is a signal that can waited on.

func AllAwaitables

func AllAwaitables(awaitables ...Awaitable) Awaitable

AllAwaitables creates an aggregated Awaitable waiting for all of the given Awaitable(s)

func AnyAwaitables

func AnyAwaitables(awaitables ...Awaitable) Awaitable

AnyAwaitables creates an aggregated Awaitable waiting for any of the given Awaitable(s)

func NewWaitGroupAwaitable

func NewWaitGroupAwaitable(waitGroup *sync.WaitGroup) Awaitable

NewWaitGroupAwaitable creates an Awaitable waiting on the given sync.WaitGroup The waiting on the given WaitGroup starts immediately in this call and ends when the counter reaches zero. Subsequent changing of the counter would have no effect - a new Awaitable would need to be created.

type AwaitableBase

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

AwaitableBase provides waiting methods by a channel (to be closed)

func (AwaitableBase) After

func (awaitable AwaitableBase) After(timeout time.Duration) Awaitable

After creates an awaitable which is signaled after this awaitable and certain duration of time It returns a chained Awaitable; The current Awaitable can still be waited on.

func (*AwaitableBase) Channel

func (awaitable *AwaitableBase) Channel() <-chan Void

Channel returns the internal channel that can be used in more complex situations. The returned channel is meant to be read-only and select should either be pending or not-ok, because the signal is done by closing the channel, not by sending any message.

func (AwaitableBase) Next

func (awaitable AwaitableBase) Next(action func()) Awaitable

Next chains an action to be executed when the current Awaitable is done/signaled (no timeout) It returns a chained Awaitable; The current Awaitable can still be waited on.

func (*AwaitableBase) Peek

func (awaitable *AwaitableBase) Peek() bool

Peek returns true if the signal has come. It doesn't wait.

func (*AwaitableBase) Wait

func (awaitable *AwaitableBase) Wait(timeout time.Duration) bool

Wait waits for the signal until specified timeout. Returns true if sucessful or false if timeout

func (*AwaitableBase) WaitForever

func (awaitable *AwaitableBase) WaitForever()

WaitForever waits for the signal

func (*AwaitableBase) WaitTimer

func (awaitable *AwaitableBase) WaitTimer(timerC <-chan time.Time) bool

WaitTimer waits for the signal until the timer is triggered (by time/timer.C) Returns true if sucessful or false if timer is triggered

type SignalAwaitable

type SignalAwaitable struct {
	AwaitableBase
}

SignalAwaitable is a one-time signal that can waited on. It's implemented by a simple channel without any message

func NewSignalAwaitable

func NewSignalAwaitable() *SignalAwaitable

NewSignalAwaitable creates a SignalAwaitable / one-time signal to be waited on.

func (*SignalAwaitable) Signal

func (awaitable *SignalAwaitable) Signal()

Signal marks the Awaitable to notify the awaiter(s) It can be only called once or panic

type Void

type Void struct {
}

Void is an empty structure

Jump to

Keyboard shortcuts

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