You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

package loop
import (
// subscribeAndLogUpdates subscribes to updates for a swap and logs them. This
// function will block, so should run as a goroutine. Note that our subscription
// does not survive server restarts; we will simply not have update logs if the
// server restarts during swap execution.
func subscribeAndLogUpdates(ctx context.Context, hash lntypes.Hash,
log *swap.PrefixLog, subscribe func(context.Context,
lntypes.Hash) (<-chan *ServerUpdate, <-chan error, error)) {
subscribeChan, errChan, err := subscribe(ctx, hash)
if err != nil {
log.Errorf("could not get swap subscription: %v", err)
for {
select {
// Consume any updates and log them.
case update := <-subscribeChan:
log.Infof("Server update: %v received, "+
"timestamp: %v", update.State, update.Timestamp)
// If we get an error from the server, we check whether it is
// due to server exit, or restart, and log this information
// for the client. Otherwise, we just log non-nil errors.
case err := <-errChan:
switch err {
case errServerSubscriptionComplete:
log.Infof("swap subscription: %v", err)
case nil:
log.Errorf("swap subscription error: %v", err)
// Exit if our context is cancelled.
case <-ctx.Done():