Skip to content

Commit

Permalink
Merge pull request #9 from crackcomm/master
Browse files Browse the repository at this point in the history
Check if doneChan is not nil.
  • Loading branch information
mreiferson committed Sep 26, 2013
2 parents 666829c + c8ab4cf commit f148dc5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ func (w *Writer) Stop() {
// PublishAsync publishes a message body to the specified topic
// but does not wait for the response from `nsqd`.
//
// When the Writer eventually receives the response from `nsqd`, the supplied `doneChan`
// When the Writer eventually receives the response from `nsqd`,
// the supplied `doneChan` (if specified)
// will receive a `WriterTransaction` instance with the supplied variadic arguments
// (and the response `FrameType`, `Data`, and `Error`)
func (w *Writer) PublishAsync(topic string, body []byte, doneChan chan *WriterTransaction, args ...interface{}) error {
Expand All @@ -103,7 +104,8 @@ func (w *Writer) PublishAsync(topic string, body []byte, doneChan chan *WriterTr
// MultiPublishAsync publishes a slice of message bodies to the specified topic
// but does not wait for the response from `nsqd`.
//
// When the Writer eventually receives the response from `nsqd`, the supplied `doneChan`
// When the Writer eventually receives the response from `nsqd`,
// the supplied `doneChan` (if specified)
// will receive a `WriterTransaction` instance with the supplied variadic arguments
// (and the response `FrameType`, `Data`, and `Error`)
func (w *Writer) MultiPublishAsync(topic string, body [][]byte, doneChan chan *WriterTransaction, args ...interface{}) error {
Expand Down Expand Up @@ -288,7 +290,7 @@ func (w *Writer) messageRouter() {
t.FrameType = frameType
t.Data = data
t.Error = err
t.doneChan <- t
t.done()
case <-w.closeChan:
goto exit
}
Expand All @@ -302,7 +304,7 @@ exit:
func (w *Writer) transactionCleanup() {
for _, t := range w.transactions {
t.Error = ErrNotConnected
t.doneChan <- t
t.done()
}
w.transactions = w.transactions[:0]
}
Expand Down Expand Up @@ -330,3 +332,9 @@ exit:
w.wg.Done()
log.Printf("[%s] exiting readLoop()", w)
}

func (t *WriterTransaction) done() {
if t.doneChan != nil {
t.doneChan <- t
}
}

0 comments on commit f148dc5

Please sign in to comment.