Documentation
¶
Overview ¶
Package concurrency contain some functions to support concurrent programming. eg, goroutine, channel, async.
Index ¶
- type Channel
- func (c *Channel[T]) Bridge(ctx context.Context, chanStream <-chan <-chan T) <-chan T
- func (c *Channel[T]) FanIn(ctx context.Context, channels ...<-chan T) <-chan T
- func (c *Channel[T]) Generate(ctx context.Context, values ...T) <-chan T
- func (c *Channel[T]) Or(channels ...<-chan T) <-chan T
- func (c *Channel[T]) OrDone(ctx context.Context, channel <-chan T) <-chan T
- func (c *Channel[T]) Repeat(ctx context.Context, values ...T) <-chan T
- func (c *Channel[T]) RepeatFn(ctx context.Context, fn func() T) <-chan T
- func (c *Channel[T]) Take(ctx context.Context, valueStream <-chan T, number int) <-chan T
- func (c *Channel[T]) Tee(ctx context.Context, in <-chan T) (<-chan T, <-chan T)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel[T any] struct { }
Channel is a logic object which can generate or manipulate go channel all methods of Channel are in the book tilted《Concurrency in Go》
func (*Channel[T]) Bridge ¶
Bridge link multiply channels into one channel. Play: Todo
Example ¶
Output: 1 2 3 4 5
func (*Channel[T]) FanIn ¶
FanIn merge multiple channels into one channel. Play: Todo
Example ¶
Output:
func (*Channel[T]) Generate ¶
Generate creates channel, then put values into the channel. Play: Todo
Example ¶
Output: 1 2 3
func (*Channel[T]) Or ¶
func (c *Channel[T]) Or(channels ...<-chan T) <-chan T
Or read one or more channels into one channel, will close when any readin channel is closed. Play: Todo
Example ¶
Output: ok
func (*Channel[T]) OrDone ¶
OrDone read a channel into another channel, will close until cancel context. Play: Todo
Example ¶
Output: 1 1 1
func (*Channel[T]) Repeat ¶
Repeat create channel, put values into the channel repeatly until cancel the context. Play: Todo
Example ¶
Output: 1 2 1 2
func (*Channel[T]) RepeatFn ¶
RepeatFn create a channel, excutes fn repeatly, and put the result into the channel until close context. Play: Todo
Example ¶
Output: hello hello hello