Fix example

This commit is contained in:
Vladimir Mihailenco 2018-07-24 10:48:14 +03:00
parent 62fa0f88da
commit 480db94d33
1 changed files with 7 additions and 1 deletions

View File

@ -324,11 +324,17 @@ func ExamplePubSub() {
pubsub := client.Subscribe("mychannel1") pubsub := client.Subscribe("mychannel1")
defer pubsub.Close() defer pubsub.Close()
// Wait for confirmation that subscription is created before publishing anything.
_, err := pubsub.Receive()
if err != nil {
panic(err)
}
// Go channel which receives messages. // Go channel which receives messages.
ch := pubsub.Channel() ch := pubsub.Channel()
// Publish a message. // Publish a message.
err := client.Publish("mychannel1", "hello").Err() err = client.Publish("mychannel1", "hello").Err()
if err != nil { if err != nil {
panic(err) panic(err)
} }