channel

package
v0.0.0-...-9db4afe Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: Apache-2.0 Imports: 3 Imported by: 4

README

golang 队列

使用例子:

package main

import (
    "github.com/luopengift/golibs/channel"
    "time"
    "fmt"
)

func main() {
    var max_works int64 = 100
    c := channel.NewChannel(max_works)
    go func() {
        for {
            fmt.Println(c)
            time.Sleep(500 * time.Millisecond)
        }
    }()
    for i := 0; i < 20; i++ {
            c.Run(func() error {
                fmt.Println(fmt.Sprintf("groutine no.%d start,time %v", i, time.Now().Format("15:04:05")))
                time.Sleep(2 * time.Second)
                fmt.Println(fmt.Sprintf("groutine no.%d end,time %v", i, time.Now().Format("15:04:05")))
                return nil
            })
    }
    select{}

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

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

func NewChannel

func NewChannel(max int) *Channel

func (*Channel) Add

func (ch *Channel) Add()

往管道中放入一个标记,记录活跃数值

func (*Channel) Cap

func (ch *Channel) Cap() int

func (*Channel) Close

func (ch *Channel) Close() error

func (*Channel) Count

func (ch *Channel) Count()

计数

func (*Channel) Done

func (ch *Channel) Done()

从管道中取出一个标记,减少活跃数值

func (*Channel) Get

func (ch *Channel) Get() (interface{}, bool)

从管道中读数据

func (*Channel) Idle

func (ch *Channel) Idle() int

func (*Channel) Len

func (ch *Channel) Len() int

func (*Channel) Put

func (ch *Channel) Put(v interface{}) error

往管道中写数据

func (*Channel) Run

func (ch *Channel) Run(fun func() error) error

func (*Channel) String

func (ch *Channel) String() string

func (*Channel) Total

func (ch *Channel) Total() int64

Jump to

Keyboard shortcuts

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