@@ -222,3 +222,49 @@ func (s *API) FetchLatestEngineVersion(engineName string) (*EngineVersion, error
222222 }
223223 return latestEngineVersion , nil
224224}
225+
226+ // WaitForSnapshotRequest is used by WaitForSnapshot method.
227+ type WaitForSnapshotRequest struct {
228+ SnapshotID string
229+ Region scw.Region
230+ Timeout * time.Duration
231+ RetryInterval * time.Duration
232+ }
233+
234+ func (s * API ) WaitForSnapshot (req * WaitForSnapshotRequest , opts ... scw.RequestOption ) (* Snapshot , error ) {
235+ timeout := defaultTimeout
236+ if req .Timeout != nil {
237+ timeout = * req .Timeout
238+ }
239+ retryInterval := defaultRetryInterval
240+ if req .RetryInterval != nil {
241+ retryInterval = * req .RetryInterval
242+ }
243+
244+ terminalStatus := map [SnapshotStatus ]struct {}{
245+ SnapshotStatusReady : {},
246+ SnapshotStatusError : {},
247+ SnapshotStatusLocked : {},
248+ }
249+
250+ snapshot , err := async .WaitSync (& async.WaitSyncConfig {
251+ Get : func () (interface {}, bool , error ) {
252+ res , err := s .GetSnapshot (& GetSnapshotRequest {
253+ SnapshotID : req .SnapshotID ,
254+ Region : req .Region ,
255+ }, opts ... )
256+ if err != nil {
257+ return nil , false , err
258+ }
259+ _ , isTerminal := terminalStatus [res .Status ]
260+
261+ return res , isTerminal , nil
262+ },
263+ Timeout : timeout ,
264+ IntervalStrategy : async .LinearIntervalStrategy (retryInterval ),
265+ })
266+ if err != nil {
267+ return nil , errors .Wrap (err , "waiting for snapshot failed" )
268+ }
269+ return snapshot .(* Snapshot ), nil
270+ }
0 commit comments