docker / go-events

Composable event distribution for Go
Apache License 2.0
131 stars 22 forks source link

Implement dispatcher type for efficient filtering #2

Open stevvooe opened 8 years ago

stevvooe commented 8 years ago

Broadcaster distributing to a set of filtered sinks is fairly efficient in practice but still requires O(N) for every message sent. Provide the following interface definition to allow implementation of efficient event dispatch:

func NewDispatcher(selector Selector) *Dispatcher

type Selector interface {
    // Select zero or more sinks on which the event should be sent.
    Select(event Event) []Sink
}

This will allow events to be dispatched to a large set of listeners without incurring O(N) overhead for all messages.

This can also be used to implement load balancing of messages to support worker queues.