Skip to content
A multicast channel library for Go with a simple API and familiar semantics
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml
LICENSE
README.md
channel.go
channel_test.go
debug.test
listener.go
listener_test.go
readme_test.go

README.md

Multicast Build Status GoDoc

Multi-subscriber channels for Golang

The multicast module provides single-writer, multiple-reader semantics around Go channels. It attempts to maintain semantics similar to those offered by standard Go channels while guaranteeing parallel delivery (slow consumers won't hold up delivery to other listeners) and guaranteeing delivery to all registered listeners when a message is published.

Features

  • Simple API if you know how to use channels then you'll be able to use multicast without learning anything special.
  • Similar Semantics to core channels mean that your approach to reasoning around channels doesn't need to change.
  • Low Overheads with linear memory growth as your number of listeners increases and no buffer overheads.

Example

import (
    "fmt"

    "github.com/SierraSoftworks/multicast"
)

func main() {
    c := multicast.New()

	go func() {
		l := c.Listen()
		for msg := range l.C {
			fmt.Printf("Listener 1: %s\n", msg)
		}
        fmt.Println("Listener 1 Closed")
	}()

	go func() {
		l := c.Listen()
		for msg := range l.C {
			fmt.Printf("Listener 2: %s\n", msg)
		}
        fmt.Println("Listener 2 Closed")
	}()

	c.C <- "Hello World!"
	c.Close()
}

Architecture

Multicast implements its channels as a linked list of listeners which automatically forward messages they receive to the next listener before exposing them on their C channel.

This approach removes the need to maintain an array of listeners belonging to a channel and greatly simplifies the implementation.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.