Skip to content

Commit

Permalink
rink: Allow for Run to be called later
Browse files Browse the repository at this point in the history
Summary: Separate Create and Run so that we can join the cluster at a later point.
  • Loading branch information
adamhicks committed Dec 1, 2023
1 parent 92be16f commit cb3025e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions v2/rink.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ type Rink struct {
// Call Shutdown to stop and clean up rink roles.
// Use Roles to access individual roles.
func New(cli *clientv3.Client, name string, opts ...Option) *Rink {
s := Create(cli, name, opts...)
go s.Run()
return s
}

// Create creates a Rink client, ready to join the cluster.
// Call Run to join the cluster and assign roles.
func Create(cli *clientv3.Client, name string, opts ...Option) *Rink {
ctx, cancel := context.WithCancel(context.Background())
s := &Rink{
cli: cli,
Expand All @@ -104,23 +112,22 @@ func New(cli *clientv3.Client, name string, opts ...Option) *Rink {
options: buildOptions(opts),
}
s.Roles = NewRoles(name, s.options.RolesOptions)

go s.run(ctx)
return s
}

// Shutdown will synchronously release all locked roles, shutdown the cluster, and
// revoke the current Session.
func (s *Rink) Shutdown(ctx context.Context) {
s.cancel()
s.options.Log.Debug(s.ctx, "shutting down rink")
s.options.Log.Debug(ctx, "shutting down rink")
select {
case <-s.finished:
case <-ctx.Done():
}
}

func (s *Rink) run(ctx context.Context) {
func (s *Rink) Run() {
ctx := s.ctx
s.options.Log.Debug(ctx, "running rink")
defer s.options.Log.Debug(ctx, "stopped rink")

Expand Down

0 comments on commit cb3025e

Please sign in to comment.