Skip to content

nitroshare/gobroadcast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gobroadcast

Build Status Coverage Status Go Reference MIT License

This package provides an implementation of the fan-out pattern.

Sending on a channel in Go normally results in a single channel receiving the value, even if multiple goroutines are receiving on the channel. Instead, this package provides Broadcaster, which multiple goroutines can Subscribe() to and receive copies of data Sent():

import "github.com/nitroshare/gobroadcast"

// Create the broadcaster
b := gobroadcast.New[int]()

// Subscribe to the broadcasts (returns a channel that receives them)
c := b.Subscribe()

// Broadcast values
b.Send(0)
b.Send(50)
b.Send(100)

// Unsubscribe from broadcasts
b.Unsubscribe(c)

// Shut down broadcaster (implicitly closing the channel for all subscribers)
b.Close()

About

Simple implementation of the fanout / broadcast pattern in Go

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages