pubsub

package
v0.0.0-...-dc1fca4 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

README

PubSub

Usage

package main

import (
  "github.com/dynport/dgtk/pubsub"
  "log"
)

func init() {
  log.SetFlags(0)
}

type User struct {
  name string
}

func main() {
  ps := pubsub.New()
  stringSubscription := ps.Subscribe(func(m string) {
    log.Printf("got string %q", m)
  })
  defer stringSubscription.Close()

  userSubscription := ps.Subscribe(func(u *User) {
    log.Printf("got user %+v", u)
  })
  defer userSubscription.Close()

  ps.Publish("hello")
  ps.Publish("world")

  ps.Publish(&User{name: "Hans"})
  ps.Publish(&User{name: "Meyer"})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

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

func NewMessage

func NewMessage(key string, payload interface{}) *Message

func (*Message) CreatedAt

func (message *Message) CreatedAt() time.Time

func (*Message) Key

func (message *Message) Key() string

func (*Message) Payload

func (message *Message) Payload() interface{}

type PubSub

type PubSub struct {
	Stats
	// contains filtered or unexported fields
}

func New

func New() *PubSub

func (*PubSub) Publish

func (pubsub *PubSub) Publish(i interface{}) (e error)

func (*PubSub) Subscribe

func (pubsub *PubSub) Subscribe(i interface{}) *Subscription

func (*PubSub) SubscribersCount

func (pubsub *PubSub) SubscribersCount() int

type Stats

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

func (*Stats) Dispatched

func (stats *Stats) Dispatched() int64

func (*Stats) Ignored

func (stats *Stats) Ignored() int64

func (*Stats) MessageDispatched

func (stats *Stats) MessageDispatched()

func (*Stats) MessageIgnored

func (stats *Stats) MessageIgnored()

func (*Stats) MessageReceived

func (stats *Stats) MessageReceived()

func (*Stats) Received

func (stats *Stats) Received() int64

func (*Stats) StartCollecting

func (stats *Stats) StartCollecting()

type Subscription

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

func (*Subscription) Close

func (subscription *Subscription) Close() error

func (*Subscription) Matches

func (subscription *Subscription) Matches(v reflect.Value) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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