sendaround

package module
v0.0.0-...-81e1d02 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: MIT Imports: 0 Imported by: 0

README

go-sendaround

Go Documentation

A wrapper around a list of callback functions to be called when data is published to named subscription lists.

Usage

Example
package main

import (
	"fmt"
	"time"

	"fmac.dev/go-sendaround"
)

func main() {
	sendaround.Init()

	sendaround.Sub("chan_1", func(data interface{}) {
		fmt.Println(data)
	})
	sendaround.Sub("chan_2", func(data interface{}) {
		fmt.Println(data)
	})
	sendaround.Sub("chan_2", func(data interface{}) {
		fmt.Println(data)
	})

	sendaround.Pub("chan_1", 123)
	sendaround.Pub("chan_2", struct{ greet string }{"hi!"})

	time.Sleep(time.Millisecond)
}
$ go build main.go && ./main
{hi!}
123
{hi!}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Destroy

func Destroy()

Destroy causes the receiver channel to be closed.

func Init

func Init()

Init starts the receiver goroutine.

func Pub

func Pub(chName string, data interface{})

Pub publishes a message to a subscription list.

func Sub

func Sub(chName string, f Callback)

Sub adds a callback to a subscription list.

Types

type Callback

type Callback func(data interface{})

Callback is the function type that handling received messages.

Jump to

Keyboard shortcuts

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