Wait for response on socket when sending

It appears that signald doesn't like not being able to send something back on
the socket.
This commit is contained in:
Maarten Everts 2020-09-04 16:10:28 +02:00
parent 9248417773
commit 599c65adb2

View file

@ -19,6 +19,7 @@ import (
"log" "log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"time"
"git.callpipe.com/finn/signald-go/signald" "git.callpipe.com/finn/signald-go/signald"
"git.callpipe.com/finn/signald-go/signald/client-protocol/v1" "git.callpipe.com/finn/signald-go/signald/client-protocol/v1"
@ -59,6 +60,20 @@ var sendCmd = &cobra.Command{
request.AttachmentFilenames = []string{attachment} request.AttachmentFilenames = []string{attachment}
} }
s.SendRequest(request) s.SendRequest(request)
timeout := 10
// Wait for the response
c := make(chan signald.Response)
go s.Listen(c)
select {
case <-c:
log.Println("Ok.")
case <-time.After(1 * time.Second):
// But timeout after a while
log.Fatalf("Timeout after %d seconds\n", timeout)
}
}, },
} }