()
| 23 | } |
| 24 | |
| 25 | func Example_providers() { |
| 26 | if os.Getenv("ETCD_ADDR") == "" { |
| 27 | fmt.Println("set ETCD_ADDR to run this example") |
| 28 | return |
| 29 | } |
| 30 | c := core.Default(core.WithInline("log.level", "none")) |
| 31 | c.Provide(leader.Providers(leader.WithDriver(AlwaysLeaderDriver{}))) |
| 32 | |
| 33 | c.Invoke(func(dispatcher contract.Dispatcher, sts *leader.Status) { |
| 34 | dispatcher.Subscribe(events.Listen(leader.OnStatusChanged, func(ctx context.Context, event interface{}) error { |
| 35 | // Becomes true when campaign succeeds and becomes false when resign |
| 36 | fmt.Println(event.(leader.OnStatusChangedPayload).Status.IsLeader()) |
| 37 | return nil |
| 38 | })) |
| 39 | }) |
| 40 | |
| 41 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
| 42 | defer cancel() |
| 43 | c.Serve(ctx) |
| 44 | |
| 45 | // Output: |
| 46 | // true |
| 47 | // false |
| 48 | } |
nothing calls this directly
no test coverage detected