pubsub

package module
v0.0.0-...-17eb44f Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2017 License: MIT Imports: 0 Imported by: 2

README

Installation

go get github.com/jbrodriguez/pubsub

Documentation

View the API Documentation.

License

MIT

Credits

This is a fork of pubsub.

Check the original README below.

Original README

Install pubsub with,

go get github.com/cskr/pubsub

View the API Documentation.

License

Copyright (c) 2013, Chandra Sekar S
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Documentation

Overview

Package pubsub implements a simple multi-topic pub-sub library.

Topics must be strings and messages of type Mailbox can be published. A topic can have any number of subcribers and all of them receive messages published on the topic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mailbox

type Mailbox struct {
	Topic   string
	Content *Message
}

type Message

type Message struct {
	Id      uint64
	Payload interface{}
	Reply   chan interface{}
}

type PubSub

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

PubSub is a collection of topics.

func New

func New(capacity int) *PubSub

New creates a new PubSub and starts a goroutine for handling operations. The capacity of the channels created by Sub and SubOnce will be as specified.

func (*PubSub) Close

func (ps *PubSub) Close(topics ...string)

Close closes all channels currently subscribed to the specified topics. If a channel is subscribed to multiple topics, some of which is not specified, it is not closed.

func (*PubSub) CreateMailbox

func (ps *PubSub) CreateMailbox() chan *Mailbox

CreateMailbox creates a channel that will be used to subscribe to and send messages to

func (*PubSub) Pub

func (ps *PubSub) Pub(msg *Message, topics ...string)

Pub publishes the given message to all subscribers of the specified topics.

func (*PubSub) Shutdown

func (ps *PubSub) Shutdown()

Shutdown closes all subscribed channels and terminates the goroutine.

func (*PubSub) Sub

func (ps *PubSub) Sub(ch chan *Mailbox, topics ...string)

Sub associates a channel to messages published on any of the specified topics.

func (*PubSub) SubOnce

func (ps *PubSub) SubOnce(ch chan *Mailbox, topics ...string)

SubOnce is similar to Sub, but only the first message published, after subscription, on any of the specified topics can be received.

func (*PubSub) Unsub

func (ps *PubSub) Unsub(ch chan *Mailbox, topics ...string)

Unsub unsubscribes the given channel from the specified topics. If no topic is specified, it is unsubscribed from all topics.

Jump to

Keyboard shortcuts

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