photoprism/internal/event/hub.go
Michael Mayer 6e74f16a77 Auth: Open album share links in the regular user interface #98 #782
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-10-02 11:38:30 +02:00

40 lines
764 B
Go

package event
import (
"strings"
"github.com/leandro-lugaresi/hub"
)
type Hub = hub.Hub
type Data = hub.Fields
type Message = hub.Message
const TopicSep = "."
var channelCap = 100
var sharedHub = NewHub()
func NewHub() *Hub {
return hub.New()
}
func SharedHub() *Hub {
return sharedHub
}
// Subscribe creates a topic subscription and returns i
func Subscribe(topics ...string) hub.Subscription {
return SharedHub().NonBlockingSubscribe(channelCap, topics...)
}
// Unsubscribe deletes the subscription of a topic.
func Unsubscribe(s hub.Subscription) {
SharedHub().Unsubscribe(s)
}
// Topic splits the topic name into the channel and event names.
func Topic(topic string) (ch, ev string) {
ch, ev, _ = strings.Cut(topic, TopicSep)
return ch, ev
}