...

Package channel

import "simonwaldherr.de/go/golibs/channel"
Overview
Index
Examples

Overview ▾

type Communication

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

func Init

func Init() *Communication

Example

Code:

var w sync.WaitGroup
var receiver = make(map[int]chan interface{})

w.Add(5)

con := channel.Init()

for i := 0; i < 5; i++ {
    receiver[i] = con.AddReceiver()

    go func(j int) {
        fmt.Println(<-receiver[j])
        w.Done()
    }(i)
}

transmitter01 := con.AddTransmitter()

transmitter01 <- "Hello World"

w.Wait()

for i := 0; i < 5; i++ {
    con.CloseReceiver(receiver[i])
}

Output:

Hello World
Hello World
Hello World
Hello World
Hello World

func (*Communication) AddReceiver

func (hub *Communication) AddReceiver() chan interface{}

func (*Communication) AddTransmitter

func (hub *Communication) AddTransmitter() chan<- interface{}

func (*Communication) CloseReceiver

func (hub *Communication) CloseReceiver(ch chan interface{}) int

func (*Communication) CountReceiver

func (hub *Communication) CountReceiver() int