Documentation ¶
Index ¶
- Variables
- func DeepCopy[T any](t *T) T
- func GetFunctionName(i interface{}) string
- func ToSnakeCase(str string) string
- type Event
- func (e *Event[D]) AddBufferedHandler(ctx context.Context, id string, fn func([]*D), size uint, ...) RemoveHandlerFn
- func (e *Event[D]) AddHandler(ctx context.Context, id string, fn func(*D)) RemoveHandlerFn
- func (e *Event[D]) NumHandlers() int
- func (e *Event[D]) Topic() string
- func (e *Event[D]) Trigger(ctx context.Context, data D)
- func (e *Event[D]) WaitForBufferedData(ctx context.Context, selector func(*D) bool, size uint, timeout time.Duration) (<-chan []*D, RemoveHandlerFn)
- func (e *Event[D]) WaitForData(ctx context.Context, selector func(*D) bool) (<-chan *D, RemoveHandlerFn)
- type EventData
- type Logger
- type Metadata
- type RemoveHandlerFn
Constants ¶
This section is empty.
Variables ¶
var ContextKeyPublisherID = contextKey("publisher_id")
Functions ¶
func GetFunctionName ¶
func GetFunctionName(i interface{}) string
GetFunctionName returns the function name.
Types ¶
type Event ¶
type Event[D EventData] struct { // contains filtered or unexported fields }
func (*Event[D]) AddBufferedHandler ¶
func (e *Event[D]) AddBufferedHandler(ctx context.Context, id string, fn func([]*D), size uint, timeout time.Duration) RemoveHandlerFn
AddBufferedHandler registers a new buffered handler with a unique id, function fn, size and timeout.
If id is empty, a uuidV4 will be generated instead. If size is zero, a default value of 100 is used. If timeout is zero, a default value of 1 second is used. Events are buffered and sent when either size or timeout is reached.
IMPORTANT:
- ctx must be property hydrated with the customer metadata.
- fn is not nil.
- fn must not block forever as we have a limited amount of goroutines in our pool.
func (*Event[D]) AddHandler ¶
func (e *Event[D]) AddHandler(ctx context.Context, id string, fn func(*D)) RemoveHandlerFn
AddHandler registers a new handler with a unique id and function fn.
If id is empty, a uuidV4 will be generated instead.
IMPORTANT:
- ctx must be property hydrated with the customer metadata.
- fn is not nil.
- fn must not block forever as we have a limited amount of goroutines in our pool.
func (*Event[D]) NumHandlers ¶
func (*Event[D]) WaitForBufferedData ¶
func (e *Event[D]) WaitForBufferedData(ctx context.Context, selector func(*D) bool, size uint, timeout time.Duration) (<-chan []*D, RemoveHandlerFn)
WaitForBufferedData adds a convenience handler for synchronous buffered event subscription.
func (*Event[D]) WaitForData ¶
func (e *Event[D]) WaitForData(ctx context.Context, selector func(*D) bool) (<-chan *D, RemoveHandlerFn)
WaitForData adds a convenience handler for synchronous event subscription.
type Logger ¶
type Logger interface { Debug(args ...interface{}) Info(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) Fatal(args ...interface{}) Debugf(template string, args ...interface{}) Infof(template string, args ...interface{}) Warnf(template string, args ...interface{}) Errorf(template string, args ...interface{}) Fatalf(template string, args ...interface{}) }
type Metadata ¶
type Metadata struct { // EventID is the unique identifier of the event. EventID string // PublisherID is the account which produced the event. PublisherID string // Time event was produced. Time time.Time }
func MetadataFromContext ¶
func (Metadata) GetMetadata ¶
type RemoveHandlerFn ¶
type RemoveHandlerFn func()