func (c *consulCoordinator) Stop() {
	close(c.sessionRenew)
	c.sessionRenew = nil
	close(c.stopCh)
	session := c.client.Session()
	log.Printf("[coordinator] Destroying session %s", c.sessionID)
	session.Destroy(c.sessionID, nil)  
}
Stop destroys the Consul session, deleting all our keys
package dagger
import (
	"fmt"
	"net"
	"strings"
	"sync"
	"time"
	log "github.com/Sirupsen/logrus"
	"github.com/cenkalti/backoff"
	"github.com/hashicorp/consul/api"
)
const (
	taskPrefix        = "dagger/tasks/"
	subscribersPrefix = "dagger/subscribers/"
	publishersPrefix  = "dagger/publishers/"
)
type ConsulConfig struct {
	Address   string
	TTL       string
	LockDelay time.Duration
}
func defaultConfig() *ConsulConfig {
	return &ConsulConfig{
		Address:   "localhost:8500",
		TTL:       "10s",
		LockDelay: 100 * time.Millisecond,
	}
}
type consulCoordinator struct {
	client *api.Client
	config *ConsulConfig
	addr   net.Addr
	sessionID    string
	sessionRenew chan struct{}
	stopCh       chan struct{}
	subscribers     map[string]*subscribersList
	subscribersLock sync.RWMutex
}
func NewConsulCoordinator(customizeConfig func(*ConsulConfig)) Coordinator {
	apiconf := api.DefaultConfig()
	conf := defaultConfig()
	if customizeConfig != nil {
		customizeConfig(conf)
	}
	apiconf.Address = conf.Address
	client, _ := api.NewClient(apiconf)
	c := &consulCoordinator{
		client:          client,
		config:          conf,
		stopCh:          make(chan struct{}),
		subscribers:     make(map[string]*subscribersList),
		subscribersLock: sync.RWMutex{},
	}
	return c
}
func (c *consulCoordinator) Start(addr net.Addr, errCh chan error) error {
	if addr == nil {
		addr = &net.TCPAddr{}
	}
	c.addr = addr
	session := c.client.Session()
	sessionOptions := &api.SessionEntry{
		Behavior:  api.SessionBehaviorDelete,
		LockDelay: c.config.LockDelay,
		TTL:       c.config.TTL,
	}
	var sessionID string
	var err error
	err = backoff.RetryNotify(func() error {
		sessionID, _, err = session.Create(sessionOptions, nil)
		return err
	}, backoff.NewExponentialBackOff(), func(err error, t time.Duration) {
		log.Println("Cannot create session, retrying in", t, ". Error:", err)
	})
	if err != nil {
		return fmt.Errorf("failed to create consul session: %v", err)
	}
	c.sessionRenew = make(chan struct{})
	c.sessionID = sessionID
	log.Println("[coordinator] Coordinator ready")
	go func() {
		errCh <- session.RenewPeriodic("5s", sessionID, nil, c.sessionRenew)
	}()
	return nil
}