notify

package
v0.0.0-...-c585647 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package notify provides a simple notification system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean()

Clean resets the subscriber map.

func NewEventID

func NewEventID() uint32

NewEventID generates a new unique event ID.

func Publish

func Publish(ctx context.Context, event uint32, payload any, cb *Callback)

Publish sends an event with a payload to all subscribers. If a callback is provided, it returns the first successful response that matches the response filter.

func Subscribe

func Subscribe(event uint32, subscriber Subscriber[any])

Subscribe adds a subscriber to the specified event.

func UnSubscribe

func UnSubscribe(event uint32, subscriber Subscriber[any])

UnSubscribe removes a subscriber from the specified event.

Types

type Callback

type Callback struct {
	CB             chan<- any
	ResponseFilter string
}

type Notify

type Notify[T any] struct {
	// contains filtered or unexported fields
}

type Publisher

type Publisher[T any] interface {
	Subscribe(event *int, subscriber Subscriber[T])
	UnSubscribe(subscriber Subscriber[T])
}

type Response

type Response[T any] struct {
	Payload T
	Error   error
	Name    string
}

type Subscriber

type Subscriber[T any] interface {
	Notify(ctx context.Context, event uint32, payload T) Response[T]
}

Jump to

Keyboard shortcuts

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