Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddEventListener ¶
func AddEventListener[T Msg](b *InProcBus, handler HandlerFuncT[T])
Example ¶
bus := ProvideBus() var ErrEmpty = errors.New("empty") AddEventListener(bus, func(ctx context.Context, query *emptypb.Empty) error { if query == nil { return ErrEmpty } fmt.Printf("event received: %T", query) return nil }) if err := bus.Publish(context.Background(), (*emptypb.Empty)(nil)); err != nil { fmt.Println("error received:", err) fmt.Println("error is ErrEmpty?", errors.Is(err, ErrEmpty)) } bus.Publish(context.Background(), &emptypb.Empty{})
Output: error received: empty error is ErrEmpty? true event received: *emptypb.Empty
Types ¶
type Bus ¶
type Bus interface { Publish(ctx context.Context, msg Msg) error AddEventListener(handler HandlerFunc) }
Bus type defines the bus interface structure.
type HandlerFunc ¶
HandlerFunc defines a handler function interface.
type InProcBus ¶
type InProcBus struct {
// contains filtered or unexported fields
}
InProcBus defines the bus structure.
func ProvideBus ¶
func ProvideBus() *InProcBus
func (*InProcBus) Publish ¶
Publish function publish a message to the bus listener.
Example ¶
bus := ProvideBus() AddEventListener(bus, func(ctx context.Context, query *emptypb.Empty) error { fmt.Printf("event received: %T", query) return nil }) bus.Publish(context.Background(), &emptypb.Empty{})
Output: event received: *emptypb.Empty
Click to show internal directories.
Click to hide internal directories.