Files
moby/vendor/github.com/docker/swarmkit/manager/watchapi/server.go
Sebastiaan van Stijn 8dedcb8c51 Bump swarmkit to 7d5d33b97794440462a04acdd3f31914da8f66f3
Relevant changes;

- swarmkit#2681 Handle an edge case in CA rotation where we reclaim CA service from an external CA
- swarmkit#2750 Use gometalinter; switch from x/net/context -> context

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-10-11 23:03:18 +02:00

57 lines
967 B
Go

package watchapi
import (
"context"
"errors"
"sync"
"github.com/docker/swarmkit/manager/state/store"
)
var (
errAlreadyRunning = errors.New("broker is already running")
errNotRunning = errors.New("broker is not running")
)
// Server is the store API gRPC server.
type Server struct {
store *store.MemoryStore
mu sync.Mutex
pctx context.Context
cancelAll func()
}
// NewServer creates a store API server.
func NewServer(store *store.MemoryStore) *Server {
return &Server{
store: store,
}
}
// Start starts the watch server.
func (s *Server) Start(ctx context.Context) error {
s.mu.Lock()
defer s.mu.Unlock()
if s.cancelAll != nil {
return errAlreadyRunning
}
s.pctx, s.cancelAll = context.WithCancel(ctx)
return nil
}
// Stop stops the watch server.
func (s *Server) Stop() error {
s.mu.Lock()
defer s.mu.Unlock()
if s.cancelAll == nil {
return errNotRunning
}
s.cancelAll()
s.cancelAll = nil
return nil
}