clientv3/concurrency/election.go
func (e *Election) Proclaim(ctx context.Context, val string) error {
	if e.leaderSession == nil {
		return ErrElectionNotLeader
	}
	client := e.session.Client()
	cmp := v3.Compare(v3.CreateRevision(e.leaderKey), "=", e.leaderRev)
	txn := client.Txn(ctx).If(cmp)
	txn = txn.Then(v3.OpPut(e.leaderKey, val, v3.WithLease(e.leaderSession.Lease())))
	tresp, terr := txn.Commit()
	if terr != nil {
		return terr
	}
	if !tresp.Succeeded {
		e.leaderKey = ""
		return ErrElectionNotLeader
	}

	e.hdr = tresp.Header
	return nil
}
func (e *Election) Proclaim(ctx context.Context, val string) error {
	if e.leaderSession == nil {
		return ErrElectionNotLeader
	}
	client := e.session.Client()
	cmp := v3.Compare(v3.CreateRevision(e.leaderKey), "=", e.leaderRev)
	txn := client.Txn(ctx).If(cmp)
	txn = txn.Then(v3.OpPut(e.leaderKey, val, v3.WithLease(e.leaderSession.Lease())))
	tresp, terr := txn.Commit()
	if terr != nil {
		return terr
	}
	if !tresp.Succeeded {
		e.leaderKey = ""
		return ErrElectionNotLeader
	}

	e.hdr = tresp.Header
	return nil
}
func ( e * Election ) Proclaim ( ctx context . Context , val string ) error { if e . leaderSession == nil { return ErrElectionNotLeader } client := e . session . Client ( ) cmp := v3 . Compare ( v3 . CreateRevision ( e . leaderKey ) , " " , e . leaderRev ) txn := client . Txn ( ctx ) . If ( cmp ) txn = txn . Then ( v3 . OpPut ( e . leaderKey , val , v3 . WithLease ( e . leaderSession . Lease ( ) ) ) ) tresp , terr := txn . Commit ( ) if terr != nil { return terr } if ! tresp . Succeeded { e . leaderKey = " " return ErrElectionNotLeader } e . hdr = tresp . Header return nil }
// Proclaim lets the leader announce a new value without another election.
Proclaim lets the leader announce a new value without another election .