Skip to content

Latest commit

 

History

History
47 lines (31 loc) · 1 KB

README.md

File metadata and controls

47 lines (31 loc) · 1 KB

chann example workflow

a unified channel package in Go

import "golang.design/x/chann"

This package requires Go 1.18.

Basic Usage

Different types of channels:

ch := chann.New[int]()                  // unbounded, capacity unlimited
ch := chann.New[func()](chann.Cap(0))   // unbufferd, capacity 0
ch := chann.New[string](chann.Cap(100)) // buffered,  capacity 100

Send and receive operations:

ch.In() <- 42
println(<-ch.Out()) // 42

Close operation:

ch.Close()

Channel properties:

ch.Len() // the length of the channel
ch.Cap() // the capacity of the channel

See https://golang.design/research/ultimate-channel for more details of the motivation of this abstraction.

License

MIT | © 2021 The golang.design Initiative Authors, written by Changkun Ou.