utils

package
v0.0.0-...-4547e52 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: GPL-3.0, Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsAny

func AsAny(err error, targets ...any) bool

func SubscribeMappedToMany

func SubscribeMappedToMany[T any, U any](
	ctx context.Context,
	broker *Broker[T],
	mapFn func(context.Context, T) ([]U, error),
) <-chan U

Creates and publishes events to a channel mapped from `inCh` (one-to-many).

Types

type Broker

type Broker[T any] struct {
	PubCh chan T // Input to broker
	// contains filtered or unexported fields
}

func NewBroker

func NewBroker[T any]() *Broker[T]

func (*Broker[T]) Publish

func (b *Broker[T]) Publish(msg T)

func (*Broker[T]) Start

func (b *Broker[T]) Start(ctx context.Context, sub event.Subscription) error

TODO: remove dependency on `event.Subscription`

func (*Broker[T]) Stop

func (b *Broker[T]) Stop()

func (*Broker[T]) Subscribe

func (b *Broker[T]) Subscribe() chan T

func (*Broker[T]) SubscribeWithCallback

func (b *Broker[T]) SubscribeWithCallback(
	ctx context.Context,
	callbackFn func(context.Context, T) error,
)

Subscribes to a new channel mapped from `inCh` (one-to-one).

func (*Broker[T]) Unsubscribe

func (b *Broker[T]) Unsubscribe(msgCh chan T)

type CategorizedError

type CategorizedError[T comparable] struct {
	Cat T
	Err error
}

func NewCategorizedError

func NewCategorizedError[T comparable](cat T, err error) *CategorizedError[T]

func (*CategorizedError[T]) Category

func (e *CategorizedError[T]) Category() T

func (*CategorizedError[T]) Error

func (e *CategorizedError[T]) Error() string

func (*CategorizedError[T]) Is

func (e *CategorizedError[T]) Is(target error) bool

Shallow comparison: categories must be equal.

func (*CategorizedError[T]) Unwrap

func (e *CategorizedError[T]) Unwrap() error

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

sync.Map with type enforcement

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

func (*Map[K, V]) Load

func (m *Map[K, V]) Load(key K) (value V)

func (*Map[K, V]) LoadAndDelete

func (m *Map[K, V]) LoadAndDelete(key K) (value V)

func (*Map[K, V]) LoadAndStore

func (m *Map[K, V]) LoadAndStore(key K, value V) V

func (*Map[K, V]) LoadOrStore

func (m *Map[K, V]) LoadOrStore(key K, value V) V

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(f func(key K, value V) bool)

func (*Map[K, V]) Store

func (m *Map[K, V]) Store(key K, value V)

Directories

Path Synopsis
This file was copied and modified from https://github.com/go-errors/errors in accordance to its license (MIT).
This file was copied and modified from https://github.com/go-errors/errors in accordance to its license (MIT).

Jump to

Keyboard shortcuts

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