// Handle gets a MultiHandle to all the plugins in this list or nil if the // list is empty. // // The returned handle MUST be closed by the caller if error was nil. func (fs Flags) Handle() (MultiHandle, error) { var ( lock sync.Mutex multi MultiHandle ) err := concurrent.Range(fs, func(_ int, f Flag) error { h, err := f.Handle() if err != nil { return err } lock.Lock() defer lock.Unlock() multi = append(multi, h) return nil }) if err == nil { return multi, nil } return nil, internal.CombineErrors(err, multi.Close()) }
func (h *transportHandle) Close() error { if !h.Running.Swap(false) { return nil // already closed } err := h.Client.Goodbye() if closer, ok := h.Transport.(io.Closer); ok { err = internal.CombineErrors(err, closer.Close()) } return err }
// Handle gets a Handle to this plugin specification. // // The returned handle MUST be closed by the caller if error was nil. func (f *Flag) Handle() (Handle, error) { transport, err := process.NewClient(f.Command) if err != nil { return nil, fmt.Errorf("failed to open plugin %q: %v", f.Name, err) } handle, err := NewTransportHandle(f.Name, transport) if err != nil { return nil, internal.CombineErrors( fmt.Errorf("failed to open plugin %q: %v", f.Name, err), transport.Close(), ) } return handle, nil }