lib: Replace done channel with contexts in and add names to util services (#6166)

This commit is contained in:
Simon Frei
2019-11-21 08:41:15 +01:00
committed by GitHub
parent 552ea68672
commit 90d85fd0a2
34 changed files with 240 additions and 218 deletions

View File

@@ -3,6 +3,7 @@
package client
import (
"context"
"crypto/tls"
"fmt"
"net/url"
@@ -51,16 +52,16 @@ type commonClient struct {
mut sync.RWMutex
}
func newCommonClient(invitations chan protocol.SessionInvitation, serve func(chan struct{}) error) commonClient {
func newCommonClient(invitations chan protocol.SessionInvitation, serve func(context.Context) error, creator string) commonClient {
c := commonClient{
invitations: invitations,
mut: sync.NewRWMutex(),
}
newServe := func(stop chan struct{}) error {
newServe := func(ctx context.Context) error {
defer c.cleanup()
return serve(stop)
return serve(ctx)
}
c.ServiceWithError = util.AsServiceWithError(newServe)
c.ServiceWithError = util.AsServiceWithError(newServe, creator)
if c.invitations == nil {
c.closeInvitationsOnFinish = true
c.invitations = make(chan protocol.SessionInvitation)