gf: Index | Examples | Files

package gchan

import ""

Package gchan provides graceful channel for no panic operations.

It's safe to call Chan.Push/Close functions repeatedly.


n := 10
c := gchan.New(n)
for i := 0; i < n; i++ {
fmt.Println(c.Len(), c.Cap())
for i := 0; i < n; i++ {


10 10



Package Files


type Chan Uses

type Chan struct {
    // contains filtered or unexported fields

Graceful channel.

func New Uses

func New(limit int) *Chan

New creates a graceful channel with given <limit>.

func (*Chan) Cap Uses

func (c *Chan) Cap() int

Cap returns the capacity of the channel.

func (*Chan) Close Uses

func (c *Chan) Close()

Close closes the channel. It is safe to be called repeatedly.

func (*Chan) Len Uses

func (c *Chan) Len() int

Len returns the length of the channel.

func (*Chan) Pop Uses

func (c *Chan) Pop() interface{}

Pop pops value from channel. If there's no value in channel, it would block to wait. If the channel is closed, it will return a nil value immediately.

func (*Chan) Push Uses

func (c *Chan) Push(value interface{}) error

Push pushes <value> to channel. It is safe to be called repeatedly.

func (*Chan) Size Uses

func (c *Chan) Size() int

See Len.

Package gchan imports 2 packages (graph). Updated 2020-03-24. Refresh now. Tools for package owners.