Files
go-sip/cmd/sip-go-agent/identity_watch.go
T

28 lines
613 B
Go

package main
import (
"context"
"errors"
"fmt"
amqp "github.com/rabbitmq/amqp091-go"
)
var errDispatcherIdentityLost = errors.New("Dispatcher MQ identity ownership lost")
func dispatcherIdentityContext(parent context.Context, done <-chan *amqp.Error) (context.Context, context.CancelFunc) {
ctx, cancel := context.WithCancelCause(parent)
go func() {
select {
case <-ctx.Done():
case err := <-done:
if err != nil {
cancel(fmt.Errorf("%w: %v", errDispatcherIdentityLost, err))
} else {
cancel(errDispatcherIdentityLost)
}
}
}()
return ctx, func() { cancel(context.Canceled) }
}