event

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2015 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package event implements an event multiplexer.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrMuxClosed = errors.New("event: mux closed")

ErrMuxClosed is returned when Posting on a closed TypeMux.

Functions

This section is empty.

Types

type Subscription

type Subscription interface {
	// Chan returns a channel that carries events.
	// Implementations should return the same channel
	// for any subsequent calls to Chan.
	Chan() <-chan interface{}

	// Unsubscribe stops delivery of events to a subscription.
	// The event channel is closed.
	// Unsubscribe can be called more than once.
	Unsubscribe()
}

Subscription is implemented by event subscriptions.

type TypeMux

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

A TypeMux dispatches events to registered receivers. Receivers can be registered to handle events of certain type. Any operation called after mux is stopped will return ErrMuxClosed.

The zero value is ready to use.

Example
Output:

Received: event.someEvent{I:5}
Received: event.someEvent{I:6}
Received: event.otherEvent{S:"whoa"}
done

func (*TypeMux) Post

func (mux *TypeMux) Post(ev interface{}) error

Post sends an event to all receivers registered for the given type. It returns ErrMuxClosed if the mux has been stopped.

func (*TypeMux) Stop

func (mux *TypeMux) Stop()

Stop closes a mux. The mux can no longer be used. Future Post calls will fail with ErrMuxClosed. Stop blocks until all current deliveries have finished.

func (*TypeMux) Subscribe

func (mux *TypeMux) Subscribe(types ...interface{}) Subscription

Subscribe creates a subscription for events of the given types. The subscription's channel is closed when it is unsubscribed or the mux is closed.

Directories

Path Synopsis
Package filter implements event filters.
Package filter implements event filters.

Jump to

Keyboard shortcuts

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