package pubsub import ( "io" cskrpubsub "github.com/cskr/pubsub" ) type PubSubWriter struct { *cskrpubsub.PubSub topic string closed bool } func NewPubSubWriter() *PubSubWriter { pipe := new(PubSubWriter) pipe.PubSub = cskrpubsub.New(1) return pipe } func (pipe *PubSubWriter) Write(p []byte) (n int, err error) { if pipe.closed { err = io.EOF return } pipe.PubSub.Pub(p, "") n = len(p) return } func (pipe *PubSubWriter) Close() (err error) { if pipe.closed { err = io.EOF return } pipe.PubSub.Shutdown() pipe.closed = true return } func (pipe *PubSubWriter) Sub() io.ReadCloser { return &PubSubReader{ channel: pipe.PubSub.Sub(""), pubsub: pipe.PubSub, closed: pipe.closed, } }