channel

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Communication

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

func Init

func Init() *Communication
Example
package main

import (
	"fmt"
	"sync"

	"simonwaldherr.de/go/golibs/channel"
)

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

Jump to

Keyboard shortcuts

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