()
| 204 | } |
| 205 | |
| 206 | func ExampleSubscription_AutoUnsubscribe() { |
| 207 | nc, _ := nats.Connect(nats.DefaultURL) |
| 208 | defer nc.Close() |
| 209 | |
| 210 | received, wanted, total := 0, 10, 100 |
| 211 | |
| 212 | sub, _ := nc.Subscribe("foo", func(_ *nats.Msg) { |
| 213 | received++ |
| 214 | }) |
| 215 | sub.AutoUnsubscribe(wanted) |
| 216 | |
| 217 | for i := 0; i < total; i++ { |
| 218 | nc.Publish("foo", []byte("Hello")) |
| 219 | } |
| 220 | nc.Flush() |
| 221 | |
| 222 | fmt.Printf("Received = %d", received) |
| 223 | } |
| 224 | |
| 225 | func ExampleConn_Close() { |
| 226 | nc, _ := nats.Connect(nats.DefaultURL) |