Skip to content

Commit

Permalink
include hostport/name to leader callback
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerinthenight committed Nov 22, 2024
1 parent fecb39a commit ed80edd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func main() {

op := hedge.New(client, ":8080", *spindleTable, *lockName, *logTable,
hedge.WithGroupSyncInterval(time.Second*5),
hedge.WithLeaderCallback(nil, func(d interface{}, m []byte) {
log.Println("callback:", string(m))
}),
hedge.WithLeaderHandler(
nil, // since this is nil, 'data' should be 'op'
func(data interface{}, msg []byte) ([]byte, error) {
Expand Down
7 changes: 6 additions & 1 deletion hedge.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,12 @@ func (op *Op) Run(ctx context.Context, done ...chan error) error {
fmt.Sprintf("hedge/spindle/lockname/%v", op.lockName),
spindle.WithDuration(op.lockTimeout),
spindle.WithId(op.hostPort),
spindle.WithLeaderCallback(op.cbLeaderData, op.cbLeader),
spindle.WithLeaderCallback(op.cbLeaderData, func(data interface{}, msg []byte) {
if op.cbLeader != nil {
m := fmt.Sprintf("%v %v", string(msg), op.Name())
op.cbLeader(data, []byte(m))
}
}),
spindle.WithLogger(op.logger),
)

Expand Down

0 comments on commit ed80edd

Please sign in to comment.