MCPcopy
hub / github.com/nats-io/nats.go / ExampleSubscription_AutoUnsubscribe

Function ExampleSubscription_AutoUnsubscribe

example_test.go:206–223  ·  example_test.go::ExampleSubscription_AutoUnsubscribe
()

Source from the content-addressed store, hash-verified

204}
205
206func 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
225func ExampleConn_Close() {
226 nc, _ := nats.Connect(nats.DefaultURL)

Callers

nothing calls this directly

Calls 6

ConnectMethod · 0.80
AutoUnsubscribeMethod · 0.80
SubscribeMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected