Skip to content

nyubroadcasting is a module go for send a message to any listeners

Notifications You must be signed in to change notification settings

Nyura95/nyubroadcasting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

newBroadcasting

go get github.com/Nyura95/nyubroadcasting

Basic usage

package main

import "log"
import "github.com/Nyura95/nyubroadcasting"

func main() {
  broadcasting := nyubroadcasting.NewBroadcasting()
	broadcasting.Start()

	go listener(broadcasting.CreateNewListener("hash2")) // start any listeners
	go listener(broadcasting.CreateNewListener("hash1"))

	broadcasting.Broadcaster <- "Hello world" // send to all listeners "hello world"
	time.Sleep(2 * time.Second)

	broadcasting.StopListener("hash1") // stop listener hash1
	time.Sleep(2 * time.Second)

	broadcasting.StopAllListener() // stop all listeners
	time.Sleep(2 * time.Second)

	broadcasting.Stop() // stop broadcaster
}

func listener(listener <-chan nyubroadcasting.ExternalCommunication) {
	for {
		com, alive := <-listener
		if !alive {
			log.Println("channel closed")
			break
		}
		log.Println(com)
	}
}

About

nyubroadcasting is a module go for send a message to any listeners

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages