broadcaster

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 2 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group[V any] struct {
	// contains filtered or unexported fields
}

func NewGroup

func NewGroup[V any]() *Group[V]

func (*Group[V]) Close

func (v *Group[V]) Close()

Close will close ALL channels and sending new messages will be no longer available

func (*Group[V]) Join

func (v *Group[V]) Join() *Member[V]

Join adds new goroutine to the group and listen for messages

func (*Group[V]) Leave

func (v *Group[V]) Leave(m *Member[V])

Leave removes specific group member and stop listening

func (*Group[V]) Send

func (v *Group[V]) Send(value V)

Send sends value to the ALL goroutines listening this group and WAITING for acks from them

func (*Group[V]) SendAsync

func (v *Group[V]) SendAsync(value V)

SendAsync sends value to all goroutines like Group.Send but won't block current thread

type Member

type Member[V any] struct {
	Out chan Message[V]
	// contains filtered or unexported fields
}

func (*Member[V]) Close

func (v *Member[V]) Close()

Close will leave current Group and close communication

func (*Member[V]) Recv

func (v *Member[V]) Recv() (msg Message[V], more bool)

Recv reads one message from channel

The "more" variable is false if channel has been closed and attempts for reading more messages will cause panic. If "more" is false just exit your read loop

func (*Member[V]) SetOnce

func (v *Member[V]) SetOnce()

SetOnce will automatically call Member.Close after reading exactly ONE VALID message

func (*Member[V]) WithFilter

func (v *Member[V]) WithFilter(f func(msg Message[V]) bool)

WithFilter is built-in message filtering feature. Messages which doesn't meet filter function will be automatically "acked"

Only valid messages can be read

Default filter is set to nil which means ALL messages are forwarded for reading

type Message

type Message[V any] struct {
	// contains filtered or unexported fields
}

func (*Message[V]) ACK

func (v *Message[V]) ACK()

ACK will tell sender that message is free to be reused if needed

Use only for SYNC communication. No action if message is ASYNC

IMPORTANT: DON'T FORGET TO CALL THIS FUNCTION IF USING Group.Send. THIS WILL BLOCK THREAD FOREVER.

func (*Message[V]) Data

func (v *Message[V]) Data() V

Data stores value sent by sender

Jump to

Keyboard shortcuts

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