hub

package
v0.0.0-...-5107381 Latest Latest
Warning

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

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

Documentation

Overview

Package hub describes event hubs that allow providers to broadcast events and allow consumers to receive them

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EntityHub

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

EntityHub is responsible for broadcasting Entity events to subscribers Example usage:

entityHub := hub.NewEntityHub(20)
go func() {
	sub, id := entityHub.Subscribe()
	defer entityHub.Unsubscribe(id)
	for {
		select {
		case payload := <-sub:
			fmt.Printf("%#v\n", payload)
		}
	}
}
entityHub.Broadcast(models.EntityEvent{StreamID: 1})

Expected output:

models.EntityEvent{StreamID:1, EntityID:0, Type:models.EntityEventType(nil)}

func NewEntityHub

func NewEntityHub(chanSize int) *EntityHub

NewEntityHub creates a new hub for broadcasting Entity events to subscribers

func (*EntityHub) Broadcast

func (h *EntityHub) Broadcast(payload models.EntityEvent)

Broadcast sends the message to all subscribers of this hub

func (*EntityHub) Subscribe

func (h *EntityHub) Subscribe() (chan *models.EntityEvent, uint64)

Subscribe adds a new hub subscriber

func (*EntityHub) Unsubscribe

func (h *EntityHub) Unsubscribe(id uint64)

Unsubscribe removes a hub subscriber

type StreamHub

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

StreamHub is responsible for broadcasting Stream events to subscribers Example usage:

streamHub := hub.NewStreamHub(20)
go func() {
	sub, id := streamHub.Subscribe()
	defer streamHub.Unsubscribe(id)
	for {
		select {
		case payload := <-sub:
			fmt.Printf("%#v\n", payload)
		}
	}
}
streamHub.Broadcast(models.StreamEvent{StreamID: 1})

Expected output:

models.StreamEvent{StreamID:1, Type:models.StreamEventType(nil)}

func NewStreamHub

func NewStreamHub(chanSize int) *StreamHub

NewStreamHub creates a new hub for broadcasting Stream events to subscribers

func (*StreamHub) Broadcast

func (h *StreamHub) Broadcast(payload models.StreamEvent)

Broadcast sends the message to all subscribers of this hub

func (*StreamHub) Subscribe

func (h *StreamHub) Subscribe() (chan *models.StreamEvent, uint64)

Subscribe adds a new hub subscriber

func (*StreamHub) Unsubscribe

func (h *StreamHub) Unsubscribe(id uint64)

Unsubscribe removes a hub subscriber

Jump to

Keyboard shortcuts

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