func (c *Client) CloseNotify() <-chan struct{} {
	return c.stop
}
CloseNotify returns a channel that is closed when the client is
closed.
package client
import (
	"encoding/json"
	"errors"
	"io"
	"net/http"
	"sync"
	"time"
	"golang.org/x/net/context"
	"github.com/mna/juggler/broker"
	"github.com/mna/juggler/internal/wswriter"
	"github.com/mna/juggler/message"
	"github.com/gorilla/websocket"
	"github.com/pborman/uuid"
)
type Client struct {
	conn *websocket.Conn
	callTimeout             time.Duration
	handler                 Handler
	readTimeout             time.Duration
	writeTimeout            time.Duration
	acquireWriteLockTimeout time.Duration
	writeLimit              int64
	stop chan struct{}
	wmu     chan struct{}  
	mu      sync.Mutex     
	results map[string]struct{}
	err     error
}
func New(conn *websocket.Conn, opts ...Option) *Client {
	wmu := make(chan struct{}, 1)
	wmu <- struct{}{}
	c := &Client{
		conn:    conn,
		stop:    make(chan struct{}),
		wmu:     wmu,
		results: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(c)
	}
	go c.handleMessages()
	return c
}
func (c *Client) handleMessages() {
	defer close(c.stop)
	for {
		_, r, err := c.conn.NextReader()
		if err != nil {
			c.mu.Lock()
			if c.err == nil {
				c.err = err
			}
			c.mu.Unlock()
			return
		}
		m, err := message.UnmarshalResponse(r)
		if err != nil {
			continue
		}
		switch m := m.(type) {
		case *message.Res:
			if ok := c.deletePending(m.Payload.For.String()); !ok {
				continue
			}
		case *message.Nack:
			if m.Payload.ForType == message.CallMsg {
				c.deletePending(m.Payload.For.String())
			}
		}
		go c.handler.Handle(context.Background(), m)
	}
}
func Dial(d *websocket.Dialer, urlStr string, reqHeader http.Header, opts ...Option) (*Client, error) {
	conn, _, err := d.Dial(urlStr, reqHeader)
	if err != nil {
		return nil, err
	}
	return New(conn, opts...), nil
}
func (c *Client) Close() error {
	c.mu.Lock()
	err := c.err
	c.mu.Unlock()
	err2 := c.conn.Close()
	<-c.stop
	if err == nil {
		err = err2
		c.mu.Lock()
		if err2 != nil {
			c.err = err2
		} else {
			c.err = errors.New("closed connection")
		}
		c.mu.Unlock()
	}
	return err
}