gchan

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package gchan provides graceful channel for no panic operations.

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

Example (Basic)
package main

import (
	"fmt"

	"github.com/gogf/gf/container/gchan"
)

func main() {
	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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chan

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

Graceful channel.

func New

func New(limit int) *Chan

New creates a graceful channel with given <limit>.

func (*Chan) Cap

func (c *Chan) Cap() int

Cap returns the capacity of the channel.

func (*Chan) Close

func (c *Chan) Close()

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

func (*Chan) Len

func (c *Chan) Len() int

Len returns the length of the channel.

func (*Chan) Pop

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

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

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

func (*Chan) Size

func (c *Chan) Size() int

See Len.

Jump to

Keyboard shortcuts

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