alpha version

This commit is contained in:
2025-02-03 17:49:29 -05:00
commit dac9e95d12
144 changed files with 5694 additions and 0 deletions

38
bus/events.go Normal file
View File

@ -0,0 +1,38 @@
package bus
import (
"fmt"
)
// Event is used to transport user data over bus.
type Event struct {
ChannelName string
Payload interface{}
}
// eventChannel stores subscriptions for channels.
type eventChannel struct {
subscribers map[string]chan Event
}
// newEventChannel creates new eventChannel.
func newEventChannel() *eventChannel {
return &eventChannel{
subscribers: make(map[string]chan Event),
}
}
// addSubscriber adds new subscriber.
func (ch *eventChannel) addSubscriber(subName string, size int) error {
if _, ok := ch.subscribers[subName]; ok {
return fmt.Errorf("subscriber %s already exists", subName)
}
ch.subscribers[subName] = make(chan Event, size)
return nil
}
// delSubscriber removes subscriber.
func (ch *eventChannel) delSubscriber(subName string) {
delete(ch.subscribers, subName)
}