Help us shape the future of Go! Take the 2026 Go Developer Survey

event

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package event provides the event bus for workflow coordination, supporting both in-memory and store-backed event publish/subscribe with WaitForEvent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

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

Bus provides high-level publish/subscribe operations over an event Store. Workflows use the Bus via WaitForEvent; external code publishes events through it to trigger workflow continuations.

func NewBus

func NewBus(store Store) *Bus

NewBus creates an event bus backed by the given store.

func (*Bus) Ack

func (b *Bus) Ack(ctx context.Context, eventID id.EventID) error

Ack acknowledges an event, marking it as consumed.

func (*Bus) Publish

func (b *Bus) Publish(ctx context.Context, name string, payload []byte, scopeAppID, scopeOrgID string) (*Event, error)

Publish creates and persists a new event, making it available for subscribers.

func (*Bus) Store

func (b *Bus) Store() Store

Store returns the underlying event store.

func (*Bus) Subscribe

func (b *Bus) Subscribe(ctx context.Context, name string, timeout time.Duration) (*Event, error)

Subscribe waits for an unacked event matching the given name. Blocks until available or timeout. Returns nil on timeout.

type Event

type Event struct {
	ID         id.EventID `json:"id"`
	Name       string     `json:"name"`
	Payload    []byte     `json:"payload,omitempty"`
	ScopeAppID string     `json:"scope_app_id,omitempty"`
	ScopeOrgID string     `json:"scope_org_id,omitempty"`
	Acked      bool       `json:"acked"`
	CreatedAt  time.Time  `json:"created_at"`
}

Event represents a named event published to the event bus. Workflows can wait for events using WaitForEvent, enabling external triggers and inter-workflow coordination.

type Store

type Store interface {
	// PublishEvent persists a new event and makes it available for subscribers.
	PublishEvent(ctx context.Context, evt *Event) error

	// SubscribeEvent waits for an unacked event matching the given name.
	// Blocks until an event is available or the timeout expires.
	// Returns nil if no event is found within the timeout.
	SubscribeEvent(ctx context.Context, name string, timeout time.Duration) (*Event, error)

	// AckEvent acknowledges an event, marking it as consumed.
	AckEvent(ctx context.Context, eventID id.EventID) error
}

Store defines the persistence contract for events.

Jump to

Keyboard shortcuts

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