allow subscription to publish to itself

This commit is contained in:
Marcelo Pires
2018-09-07 15:00:35 +02:00
parent d8a246f014
commit 58a5ed8a3f
2 changed files with 20 additions and 13 deletions

View File

@ -4,19 +4,22 @@ import (
"github.com/thesyncim/faye/message"
)
type Unsubscriber interface {
Unsubscribe(subscription *Subscription) error
}
type Unsubscriber func(subscription *Subscription) error
type Publisher func(msg message.Data) (string, error)
type Subscription struct {
id string //request Subscription ID
channel string
ok chan error //used by
unsub Unsubscriber
pub Publisher
msgCh chan *message.Message
}
func NewSubscription(id string, chanel string, unsub Unsubscriber, msgCh chan *message.Message, ok chan error) *Subscription {
func NewSubscription(id string, chanel string, unsub Unsubscriber, pub Publisher, msgCh chan *message.Message, ok chan error) *Subscription {
return &Subscription{
pub: pub,
ok: ok,
id: id,
channel: chanel,
@ -53,5 +56,9 @@ func (s *Subscription) SubscriptionResult() chan error {
}
func (s *Subscription) Unsubscribe() error {
return s.unsub.Unsubscribe(s)
return s.unsub(s)
}
func (s *Subscription) Publish(msg message.Data) (string, error) {
return s.pub(msg)
}