Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Conn struct {
- wc io.WriteCloser
- tasks sync.WaitGroup
- // ... other internal state ...
- }
- func NewConn(rwc io.ReadWriteCloser) *Conn {
- c := &Conn{wc: rwc}
- c.tasks.Add(1)
- go func() {
- defer c.tasks.Done()
- c.receive(rwc)
- }()
- return c
- }
- func (c *Conn) receive(r io.Reader) {
- for {
- msg, err := decode(r)
- if err != nil {
- return
- }
- // ... Process message ...
- }
- }
- func (c *Conn) Close() error {
- err := c.wc.Close()
- c.tasks.Wait()
- return err
- }
Add Comment
Please, Sign In to add comment