MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / ExampleHandlerFunc

Function ExampleHandlerFunc

pkg/events/handler_test.go:29–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27)
28
29func ExampleHandlerFunc() {
30 // The context typically comes from the request or something.
31 ctx := test.Context()
32
33 handler := events.HandlerFunc(func(e events.Event) {
34 fmt.Printf("Received event %v\n", e)
35 })
36
37 subCtx, unsubscribe := context.WithCancel(ctx)
38 if err := events.Subscribe(subCtx, []string{"example"}, nil, handler); err != nil {
39 panic(err)
40 }
41
42 // From this moment on, "example" events will be delivered to the handler func.
43
44 // We want to unsubscribe when this function returns.
45 defer unsubscribe()
46
47 // Note that in-transit events may still be delivered after unsubscribe returns.
48}
49
50func ExampleChannel() {
51 // The context typically comes from the request or something.

Callers

nothing calls this directly

Calls 5

ContextFunction · 0.92
HandlerFuncFunction · 0.92
SubscribeFunction · 0.92
unsubscribeFunction · 0.85
PrintfMethod · 0.45

Tested by

no test coverage detected