events

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: AGPL-3.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package events provides types to implement busses of events in an application. Senders can send events on these busses and receiver receive the events. What differenciate such a bus from a Go channel is that each event is dispatched to all receiver.

By providing a central busses to different parts of the application, these parts can communicate together without knowing each other.

Index

Constants

View Source
const DefaultManagerChannelSize = 256

Variables

View Source
var (
	ManagerClosedError = errors.New("The manager is closed")
)

Errors

Functions

This section is empty.

Types

type AsyncForwarder

type AsyncForwarder struct {
	// Filter returns true for events that must be forwarded through the channel.
	Filter func(Event) bool
	Chan   chan<- Event
}

AsyncForwarder is a simple Receiver that forward events through a channel.

func (AsyncForwarder) Close

func (self AsyncForwarder) Close()

func (AsyncForwarder) Receive

func (self AsyncForwarder) Receive(evt Event)

type Event

type Event interface {
}

type Manager

type Manager interface {

	// Send dispatch an event to all the Receivers of the Manager.
	// It takes ownership of the event.
	Send(Event) error

	// AddReceiver registers a Receiver to receive all events sent to the Manager.
	// If the Receiver is added to more than one Manager, it must be goroutine-safe.
	AddReceiver(Receiver) error

	// Close stops the Manager. Any subsequent Send will result in an error.
	// The Close method of all the Receivers of the Manager will eventually be called.
	Close() error
}

Manager dispatches events from senders to Receivers.

All its method must be goroutine-safe.

func NewAsyncManager

func NewAsyncManager(chanSize int) Manager

NewAsyncManager creates a new asynchronous Manager.

An asynchronous manager launch a goroutine that calls the Receive method of all the registered receivers for each sent event. Events are sent to this goroutine through a channel whose size is given as argument to NewAsyncManager.

type Receiver

type Receiver interface {
	Receive(Event)
	Close()
}

Receiver receives events from a Manager.

It can be assumed that the methods of a given Receiver are always called from the same goroutine by the Manager.

type ReceiverFunc

type ReceiverFunc func(Event)

ReceiverFunc turn a function into a stateless Receiver, whose Close method does nothing.

func (ReceiverFunc) Close

func (self ReceiverFunc) Close()

func (ReceiverFunc) Receive

func (self ReceiverFunc) Receive(evt Event)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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