basic

package
v3.18.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Example
package main

import (
	"go.thethings.network/lorawan-stack/v3/pkg/events"
	"go.thethings.network/lorawan-stack/v3/pkg/events/basic"
)

func main() {
	basicPubSub := basic.NewPubSub()

	// Replace the default pubsub so that we will now publish to this pub sub by default.
	events.SetDefaultPubSub(basicPubSub)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PubSub

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

PubSub is a basic event PubSub implementation.

func NewPubSub

func NewPubSub() *PubSub

NewPubSub returns a new basic event PubSub.

func (*PubSub) AddSubscription

func (e *PubSub) AddSubscription(s events.Subscription)

AddSubscription adds an event subscription to the PubSub. The exact same subscription must be used in RemoveSubscription.

func (*PubSub) Publish

func (e *PubSub) Publish(evs ...events.Event)

Publish publishes an event, which will notify all matching subscriptions.

func (*PubSub) RemoveSubscription

func (e *PubSub) RemoveSubscription(s events.Subscription)

RemoveSubscription removes an event subscription to the PubSub. This method expects the exact same subscription that was previously used in AddSubscription.

func (*PubSub) Subscribe

func (e *PubSub) Subscribe(ctx context.Context, names []string, identifiers []*ttnpb.EntityIdentifiers, hdl events.Handler) error

Subscribe starts a subscription for events that match name and identifiers. The subscription lasts until the context is canceled. The handler will be notified of matching events and must not block.

type Subscription

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

Subscription is a basic implementation of a PubSub subscription.

func NewSubscription

func NewSubscription(ctx context.Context, names []string, identifiers []*ttnpb.EntityIdentifiers, hdl events.Handler) (*Subscription, error)

NewSubscription creates a new basic PubSub subscription.

func (*Subscription) Match

func (s *Subscription) Match(evt events.Event) bool

Match returns whether the event matches the subscription.

func (*Subscription) Notify

func (s *Subscription) Notify(evt events.Event)

Notify notifies the subscription of a new matching event.

Jump to

Keyboard shortcuts

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