func (d *mdiscovery) serveStub(stub *bindings.Stub, cleanup func()) { d.mu.Lock() d.stubs[stub] = struct{}{} d.mu.Unlock() go func() { for { if err := stub.ServeRequest(); err != nil { connErr, ok := err.(*bindings.ConnectionError) if !ok || !connErr.Closed() { d.ctx.Error(err) } break } } d.mu.Lock() delete(d.stubs, stub) d.mu.Unlock() if cleanup != nil { cleanup() } }() }
func (d *delegate) run(stub *bindings.Stub, done func()) { d.mu.Lock() d.stubs[stub] = struct{}{} d.mu.Unlock() go func() { defer done() for { if err := stub.ServeRequest(); err != nil { connErr, ok := err.(*bindings.ConnectionError) if !ok || !connErr.Closed() { d.ctx.Error(err) } break } } d.mu.Lock() delete(d.stubs, stub) d.mu.Unlock() }() }