pubsub

package
v0.0.0-...-72e33f6 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package pubsub is a simple in-memory pub sub.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface {
	EventTopic() string
}

type EventTopic

type EventTopic string

func (EventTopic) EventTopic

func (e EventTopic) EventTopic() string

type HandleFunc

type HandleFunc func(ctx context.Context, event Event) error

type MiddlewareFunc

type MiddlewareFunc func(next HandleFunc) HandleFunc

type Pub

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

func NewPub

func NewPub(middleware ...MiddlewareFunc) *Pub

func (*Pub) Broadcast

func (p *Pub) Broadcast(ctx context.Context, event Event) error

func (*Pub) State

func (p *Pub) State() (State, error)

func (*Pub) Subscribe

func (p *Pub) Subscribe() SubscribeBuilder

type State

type State struct {
	SubscriberCount int
	Subscribers     []StateSubscriber
}

type StateSubscriber

type StateSubscriber struct {
	ID int
}

type Sub

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

func (Sub) Close

func (s Sub) Close()

func (Sub) Error

func (s Sub) Error() error

Error should only be called after subscription is closed.

func (Sub) Wait

func (s Sub) Wait(ctx context.Context) error

Wait blocks until the subscription is closed.

type SubscribeBuilder

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

func (SubscribeBuilder) Channel

func (b SubscribeBuilder) Channel(ctx context.Context, size int) (Sub, <-chan Event, error)

Channel creates a subscription with a channel.

func (SubscribeBuilder) Function

func (b SubscribeBuilder) Function(fn HandleFunc) (Sub, error)

Function creates a subscription with a function.

func (SubscribeBuilder) Middleware

Middleware add a middleware between the handler and publisher.

Jump to

Keyboard shortcuts

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