xdepthmaker: refactor auth binding to bindAuthSignal

This commit is contained in:
c9s 2023-12-11 17:00:25 +08:00
parent 2c3ccdf030
commit de7eb8453b
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -367,18 +367,8 @@ func (s *Strategy) CrossRun(
}
s.authedC = make(chan struct{}, 2)
s.makerSession.UserDataStream.OnAuth(func() {
select {
case s.authedC <- struct{}{}:
default:
}
})
s.hedgeSession.UserDataStream.OnAuth(func() {
select {
case s.authedC <- struct{}{}:
default:
}
})
bindAuthSignal(ctx, s.makerSession.UserDataStream, s.authedC)
bindAuthSignal(ctx, s.hedgeSession.UserDataStream, s.authedC)
go func() {
log.Infof("waiting for user data stream to get authenticated")
@ -936,3 +926,14 @@ func min(a, b int) int {
return b
}
func bindAuthSignal(ctx context.Context, stream types.Stream, c chan<- struct{}) {
stream.OnAuth(func() {
select {
case <-ctx.Done():
return
case c <- struct{}{}:
default:
}
})
}