asyncnotifications

package
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package asyncnotifications provides a channel-based async event delivery interface with implementations for WebSocket, SSE, Pusher, and Ably.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncNotifier

type AsyncNotifier interface {
	// Publish sends an event to all subscribers of the given channel.
	Publish(ctx context.Context, channel string, event *Event) error
	// Close releases resources held by the notifier.
	Close() error
}

AsyncNotifier publishes events to named channels. Implementations may deliver via WebSocket, SSE, Pusher, Ably, or other backends.

type ConnectionAcceptor

type ConnectionAcceptor interface {
	// AcceptConnection upgrades an HTTP request to a persistent connection
	// and registers it under the given channel and memberID.
	// The connection is managed internally; events published to the channel
	// will be delivered to this connection.
	AcceptConnection(w http.ResponseWriter, r *http.Request, channel, memberID string) error
}

ConnectionAcceptor is an optional interface implemented by backends that require server-side HTTP connection management (WebSocket, SSE). Callers may type-assert an AsyncNotifier to ConnectionAcceptor when they need to accept inbound client connections.

type Event

type Event struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data,omitempty"`
}

Event represents an async notification event to be published to a channel.

type NoopAsyncNotifier

type NoopAsyncNotifier struct {
	// contains filtered or unexported fields
}

NoopAsyncNotifier is a no-op implementation of AsyncNotifier.

func NewNoopAsyncNotifier

func NewNoopAsyncNotifier() (*NoopAsyncNotifier, error)

NewNoopAsyncNotifier returns a new no-op NoopAsyncNotifier.

Example
package main

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/verygoodsoftwarenotvirus/platform/v3/asyncnotifications"
)

func main() {
	notifier, err := asyncnotifications.NewNoopAsyncNotifier()
	if err != nil {
		panic(err)
	}

	err = notifier.Publish(context.Background(), "my-channel", &asyncnotifications.Event{
		Type: "greeting",
		Data: json.RawMessage(`{"message":"hello"}`),
	})

	fmt.Println(err)
}
Output:
<nil>

func (*NoopAsyncNotifier) Close

func (n *NoopAsyncNotifier) Close() error

Close is a no-op.

func (*NoopAsyncNotifier) Publish

Publish is a no-op.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL