()
| 27 | ) |
| 28 | |
| 29 | func 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 | |
| 50 | func ExampleChannel() { |
| 51 | // The context typically comes from the request or something. |
nothing calls this directly
no test coverage detected