💾 Archived View for code.pfad.fr › gohmekit › hapip › notification captured on 2024-05-26 at 14:57:42. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-12-28)
-=-=-=-=-=-=-
import "code.pfad.fr/gohmekit/hapip/notification"
type Coalescer interface { io.WriterTo // Coalescer must return itself on error (not nil!) Coalesce(io.WriterTo) (Coalescer, error) }
Coalescer allows event to be merged together to prevent sending too many events in a short time.
type Manager[Key comparable] struct { // If a connection is active, events will not be sent (to prevent corruption). // EventBuffer indicates the number of events to buffer (per connection), // which will be delivered when the connection is back to idle. EventBuffer int // CoalesceDuration will prevent too many events from being delivered after another. // Standard recommands 1s CoalesceDuration time.Duration Logger log.Logger // contains filtered or unexported fields }
Manager manages notifications. m.ConnContext & m.ConnState must be registered on the http.Server respective fields.
func (m *Manager[Key]) ConnContext(ctx context.Context, c net.Conn) context.Context
func (m *Manager[Key]) ConnState(c net.Conn, s http.ConnState)
func (m *Manager[Key]) HookConnEvents(server *http.Server)
func (m *Manager[Key]) IsSubscribed(ctx context.Context, id Key) (bool, error)
func (m *Manager[Key]) Publish(ctx context.Context, id Key, event io.WriterTo)
Publish an event. If the event is a Coalescer it might be throtteled.
func (m *Manager[Key]) Subscribe(ctx context.Context, id Key, v bool) error