Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrMuxClosed = errors.New("event: mux closed")
Functions ¶
This section is empty.
Types ¶
type Feed ¶
type Feed struct {
// contains filtered or unexported fields
}
Feed implements one-to-many subscriptions where the carrier of events is a channel.
Example (Acknowledgedfeeds) ¶
package main
import (
"fmt"
"github.com/UranusBlockStack/uranus/feed"
)
func main() {
var feed feed.Feed
type ackedfeed struct {
i int
ack chan<- struct{}
}
// Consumers wait for feeds on the feed and acknowledge processing.
done := make(chan struct{})
defer close(done)
for i := 0; i < 3; i++ {
ch := make(chan ackedfeed, 100)
sub := feed.Subscribe(ch)
go func() {
defer sub.Unsubscribe()
for {
select {
case ev := <-ch:
fmt.Println(ev.i) // "process" the feed
ev.ack <- struct{}{}
case <-done:
return
}
}
}()
}
for i := 0; i < 3; i++ {
acksignal := make(chan struct{})
n := feed.Send(ackedfeed{i, acksignal})
for ack := 0; ack < n; ack++ {
<-acksignal
}
}
}
Output: 0 0 0 1 1 1 2 2 2
func (*Feed) Subscribe ¶
func (f *Feed) Subscribe(channel interface{}) Subscription
Subscribe adds a channel to the feed.
type ForkBlockEvent ¶
type NewConfirmedEvent ¶
type NewMinedBlockEvent ¶
type NewTxsEvent ¶
type NewTxsEvent struct{ Txs []*types.Transaction }
type Subscription ¶
type Subscription interface {
Err() <-chan error
Unsubscribe()
}
type TypeMux ¶
type TypeMux struct {
// contains filtered or unexported fields
}
func (*TypeMux) Subscribe ¶
func (mux *TypeMux) Subscribe(types ...interface{}) *TypeMuxSubscription
type TypeMuxEvent ¶
type TypeMuxSubscription ¶
type TypeMuxSubscription struct {
// contains filtered or unexported fields
}
func (*TypeMuxSubscription) Chan ¶
func (s *TypeMuxSubscription) Chan() <-chan *TypeMuxEvent
func (*TypeMuxSubscription) Closed ¶
func (s *TypeMuxSubscription) Closed() bool
func (*TypeMuxSubscription) Unsubscribe ¶
func (s *TypeMuxSubscription) Unsubscribe()
Click to show internal directories.
Click to hide internal directories.