ソースを参照

Write nil rather than closing the channel

For consistency with the error case. Also give the expectation channel a buffer
of 1 to give the scheduler a bit more flexibility with its context-switches.
Evan Huus 11 年 前
コミット
d18dbad3e5
1 ファイル変更2 行追加2 行削除
  1. 2 2
      simple_producer.go

+ 2 - 2
simple_producer.go

@@ -34,7 +34,7 @@ func NewSimpleProducer(client *Client, config *ProducerConfig) (*SimpleProducer,
 
 // SendMessage produces a message to the given topic with the given key and value. To send strings as either key or value, see the StringEncoder type.
 func (sp *SimpleProducer) SendMessage(topic string, key, value Encoder) error {
-	expectation := make(chan error)
+	expectation := make(chan error, 1)
 	msg := &MessageToSend{Topic: topic, Key: key, Value: value, Metadata: expectation}
 	sp.producer.Input() <- msg
 	return <-expectation
@@ -44,7 +44,7 @@ func (sp *SimpleProducer) handleSuccesses() {
 	defer sp.wg.Done()
 	for msg := range sp.producer.Successes() {
 		expectation := msg.Metadata.(chan error)
-		close(expectation)
+		expectation <- nil
 	}
 }