Debian Codegraph @

lifesciences/apiv2beta/auxiliary.go

raw
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package lifesciences
18
19 import (
20 "context"
21 "time"
22
23 lifesciencespb "cloud.google.com/go/lifesciences/apiv2beta/lifesciencespb"
24 "cloud.google.com/go/longrunning"
25 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
26 gax "github.com/googleapis/gax-go/v2"
27 "google.golang.org/api/iterator"
28 locationpb "google.golang.org/genproto/googleapis/cloud/location"
29 )
30
31 // RunPipelineOperation manages a long-running operation from RunPipeline.
32 type RunPipelineOperation struct {
33 lro *longrunning.Operation
34 pollPath string
35 }
36
37 // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
38 //
39 // See documentation of Poll for error-handling information.
40 func (op *RunPipelineOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*lifesciencespb.RunPipelineResponse, error) {
41 opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...)
42 var resp lifesciencespb.RunPipelineResponse
43 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
44 return nil, err
45 }
46 return &resp, nil
47 }
48
49 // Poll fetches the latest state of the long-running operation.
50 //
51 // Poll also fetches the latest metadata, which can be retrieved by Metadata.
52 //
53 // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
54 // the operation has completed with failure, the error is returned and op.Done will return true.
55 // If Poll succeeds and the operation has completed successfully,
56 // op.Done will return true, and the response of the operation is returned.
57 // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
58 func (op *RunPipelineOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*lifesciencespb.RunPipelineResponse, error) {
59 opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...)
60 var resp lifesciencespb.RunPipelineResponse
61 if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
62 return nil, err
63 }
64 if !op.Done() {
65 return nil, nil
66 }
67 return &resp, nil
68 }
69
70 // Metadata returns metadata associated with the long-running operation.
71 // Metadata itself does not contact the server, but Poll does.
72 // To get the latest metadata, call this method after a successful call to Poll.
73 // If the metadata is not available, the returned metadata and error are both nil.
74 func (op *RunPipelineOperation) Metadata() (*lifesciencespb.Metadata, error) {
75 var meta lifesciencespb.Metadata
76 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
77 return nil, nil
78 } else if err != nil {
79 return nil, err
80 }
81 return &meta, nil
82 }
83
84 // Done reports whether the long-running operation has completed.
85 func (op *RunPipelineOperation) Done() bool {
86 return op.lro.Done()
87 }
88
89 // Name returns the name of the long-running operation.
90 // The name is assigned by the server and is unique within the service from which the operation is created.
91 func (op *RunPipelineOperation) Name() string {
92 return op.lro.Name()
93 }
94
95 // LocationIterator manages a stream of *locationpb.Location.
96 type LocationIterator struct {
97 items []*locationpb.Location
98 pageInfo *iterator.PageInfo
99 nextFunc func() error
100
101 // Response is the raw response for the current page.
102 // It must be cast to the RPC response type.
103 // Calling Next() or InternalFetch() updates this value.
104 Response interface{}
105
106 // InternalFetch is for use by the Google Cloud Libraries only.
107 // It is not part of the stable interface of this package.
108 //
109 // InternalFetch returns results from a single call to the underlying RPC.
110 // The number of results is no greater than pageSize.
111 // If there are no more results, nextPageToken is empty and err is nil.
112 InternalFetch func(pageSize int, pageToken string) (results []*locationpb.Location, nextPageToken string, err error)
113 }
114
115 // PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
116 func (it *LocationIterator) PageInfo() *iterator.PageInfo {
117 return it.pageInfo
118 }
119
120 // Next returns the next result. Its second return value is iterator.Done if there are no more
121 // results. Once Next returns Done, all subsequent calls will return Done.
122 func (it *LocationIterator) Next() (*locationpb.Location, error) {
123 var item *locationpb.Location
124 if err := it.nextFunc(); err != nil {
125 return item, err
126 }
127 item = it.items[0]
128 it.items = it.items[1:]
129 return item, nil
130 }
131
132 func (it *LocationIterator) bufLen() int {
133 return len(it.items)
134 }
135
136 func (it *LocationIterator) takeBuf() interface{} {
137 b := it.items
138 it.items = nil
139 return b
140 }
141
142 // OperationIterator manages a stream of *longrunningpb.Operation.
143 type OperationIterator struct {
144 items []*longrunningpb.Operation
145 pageInfo *iterator.PageInfo
146 nextFunc func() error
147
148 // Response is the raw response for the current page.
149 // It must be cast to the RPC response type.
150 // Calling Next() or InternalFetch() updates this value.
151 Response interface{}
152
153 // InternalFetch is for use by the Google Cloud Libraries only.
154 // It is not part of the stable interface of this package.
155 //
156 // InternalFetch returns results from a single call to the underlying RPC.
157 // The number of results is no greater than pageSize.
158 // If there are no more results, nextPageToken is empty and err is nil.
159 InternalFetch func(pageSize int, pageToken string) (results []*longrunningpb.Operation, nextPageToken string, err error)
160 }
161
162 // PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
163 func (it *OperationIterator) PageInfo() *iterator.PageInfo {
164 return it.pageInfo
165 }
166
167 // Next returns the next result. Its second return value is iterator.Done if there are no more
168 // results. Once Next returns Done, all subsequent calls will return Done.
169 func (it *OperationIterator) Next() (*longrunningpb.Operation, error) {
170 var item *longrunningpb.Operation
171 if err := it.nextFunc(); err != nil {
172 return item, err
173 }
174 item = it.items[0]
175 it.items = it.items[1:]
176 return item, nil
177 }
178
179 func (it *OperationIterator) bufLen() int {
180 return len(it.items)
181 }
182
183 func (it *OperationIterator) takeBuf() interface{} {
184 b := it.items
185 it.items = nil
186 return b
187 }