Documentation ¶
Overview ¶
Copyright 2019 The Swarm Authors This file is part of the Swarm library.
The Swarm library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
The Swarm library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with the Swarm library. If not, see <http://www.gnu.org/licenses/>.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PubSubChannel ¶
type PubSubChannel struct {
// contains filtered or unexported fields
}
PubSubChannel represents a pubsub system where subscriber can .Subscribe() and publishers can .Publish() or .Close(). When it publishes a message, it notifies all subscribers semi-asynchronously, meaning that each subscription will have an inbox of size inboxSize, but then a different goroutine will send those messages to the subscribers.
func (*PubSubChannel) Close ¶
func (psc *PubSubChannel) Close()
Close cancels all subscriptions closing the channels associated with them. Usually the publisher is in charge of calling Close().
func (*PubSubChannel) NumSubscriptions ¶
func (psc *PubSubChannel) NumSubscriptions() int
NumSubscriptions returns how many subscriptions are currently active.
func (*PubSubChannel) Publish ¶
func (psc *PubSubChannel) Publish(msg interface{})
Publish broadcasts a message synchronously to each subscriber inbox.
func (*PubSubChannel) Subscribe ¶
func (psc *PubSubChannel) Subscribe() *Subscription
Subscribe creates a subscription to a channel, each subscriber should keep its own Subscription instance.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription is created in PubSubChannel using pubSub.Subscribe(). Subscribers can receive using .ReceiveChannel(). or .Unsubscribe()
func (*Subscription) ID ¶
func (sub *Subscription) ID() string
ID returns a unique id in the PubSubChannel of this subscription. Useful for debugging.
func (*Subscription) IsClosed ¶
func (sub *Subscription) IsClosed() bool
IsClosed returns if the subscription is closed via Unsubscribe() or Close() in the pubSub that creates it.
func (*Subscription) MessageCount ¶
func (sub *Subscription) MessageCount() int
func (*Subscription) Pending ¶
func (sub *Subscription) Pending() int64
func (*Subscription) ReceiveChannel ¶
func (sub *Subscription) ReceiveChannel() <-chan interface{}
ReceiveChannel returns the channel where the subscriber will receive messages.
func (*Subscription) Unsubscribe ¶
func (sub *Subscription) Unsubscribe()
Unsubscribe cancels subscription from the subscriber side. Channel is marked as closed but only writer should close it.