Struct: request.Waiter

import "../ibm-cos-sdk-go/aws/request"

Overview

A Waiter provides the functionality to perform a blocking call which will wait for a resource state to be satisfied by a service.

This type should not be used directly. The API operations provided in the service packages prefixed with “WaitUntil” should be used instead.

Implemented Interfaces

s3crypto.Cipher, s3manager.ReadSeekerWriteTo, s3manager.WriterReadFrom

Structure Field Summary collapse

Method Summary collapse

Structure Field Details

Acceptors []WaiterAcceptor

Delay WaiterDelay

Logger aws.Logger

MaxAttempts int

Name string

RequestOptions []Option

Method Details

func (w *Waiter) ApplyOptions(opts ...WaiterOption)

ApplyOptions updates the waiter with the list of waiter options provided.



87
88
89
90
91
// File 'aws/request/waiter.go', line 87

func (w *Waiter) ApplyOptions(opts ...WaiterOption) { for _, fn := range opts { fn(w) } }

func (w Waiter) WaitWithContext(ctx aws.Context) error

WaitWithContext will make requests for the API operation using NewRequest to build API requests. The request's response will be compared against the Waiter's Acceptors to determine the successful state of the resource the waiter is inspecting.

The passed in context must not be nil. If it is nil a panic will occur. The Context will be used to cancel the waiter's pending requests and retry delays. Use aws.BackgroundContext if no context is available.

The waiter will continue until the target state defined by the Acceptors, or the max attempts expires.

Will return the WaiterResourceNotReadyErrorCode error code if the waiter's retryer ShouldRetry returns false. This normally will happen when the max wait attempts expires.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// File 'aws/request/waiter.go', line 168

func (w Waiter) WaitWithContext(ctx aws.Context) error { for attempt := 1; ; attempt++ { req, err := w.NewRequest(w.RequestOptions) if err != nil { waiterLogf(w.Logger, "unable to create request %v", err) return err } req.Handlers.Build.PushBack(MakeAddToUserAgentFreeFormHandler("Waiter")) err = req.Send() // See if any of the acceptors match the request's response, or error for _, a := range w.Acceptors { if matched, matchErr := a.match(w.Name, w.Logger, req, err); matched { return matchErr } } // The Waiter should only check the resource state MaxAttempts times // This is here instead of in the for loop above to prevent delaying // unnecessary when the waiter will not retry. if attempt == w.MaxAttempts { break } // Delay to wait before inspecting the resource again delay := w.Delay(attempt) if sleepFn := req.Config.SleepDelay; sleepFn != nil { // Support SleepDelay for backwards compatibility and testing sleepFn(delay) } else { sleepCtxFn := w.SleepWithContext if sleepCtxFn == nil { sleepCtxFn = aws.SleepWithContext } if err := sleepCtxFn(ctx, delay); err != nil { return awserr.New(CanceledErrorCode, "waiter context canceled", err) } } } return awserr.New(WaiterResourceNotReadyErrorCode, "exceeded wait attempts", nil) }