feed

package
v0.0.0-...-91a82d4 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: LGPL-3.0 Imports: 6 Imported by: 8

README

#feed

Implements one-to-many subscriptions where the carrier of events is a channel

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 BlockAndLogsEvent

type BlockAndLogsEvent struct {
	Block *types.Block
	Logs  types.Logs
}

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) Send

func (f *Feed) Send(value interface{}) (nsent int)

Send delivers to all subscribed channels simultaneously.

func (*Feed) Subscribe

func (f *Feed) Subscribe(channel interface{}) Subscription

Subscribe adds a channel to the feed.

type ForkBlockEvent

type ForkBlockEvent struct{ Block *types.Block }

type NewConfirmedEvent

type NewConfirmedEvent struct{ Confirmed *types.Confirmed }

type NewMinedBlockEvent

type NewMinedBlockEvent struct{ Block *types.Block }

type NewMiner

type NewMiner struct {
}

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) Post

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

func (*TypeMux) Stop

func (mux *TypeMux) Stop()

func (*TypeMux) Subscribe

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

type TypeMuxEvent

type TypeMuxEvent struct {
	Time time.Time
	Data interface{}
}

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()

Jump to

Keyboard shortcuts

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