gf: github.com/gogf/gf/g/container/gchan Index | Examples | Files

package gchan

import "github.com/gogf/gf/g/container/gchan"

Package gchan provides graceful channel for no panic operations.

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

Code:

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

Output:

10 10
0123456789

Index

Examples

Package Files

gchan.go

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 2019-06-20. Refresh now. Tools for package owners.