Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: common/retry/transient.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: more refactor Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package retry
6
7 import (
8 "time"
9
10 "github.com/luci/luci-go/common/errors"
11 "golang.org/x/net/context"
12 )
13
14 // transientOnlyIterator is an Iterator implementation that only retries errors
15 // if they are transient.
16 //
17 // (See errors.IsTransient).
18 type transientOnlyIterator struct {
19 Iterator // The wrapped Iterator.
20 }
21
22 func (i *transientOnlyIterator) Next(ctx context.Context, err error) time.Durati on {
23 if !errors.IsTransient(err) {
24 return Stop
25 }
26 return i.Iterator.Next(ctx, err)
27 }
28
29 // TransientOnly returns an Iterator that wraps another Iterator. It will fall
30 // through to the wrapped Iterator if a transient error is encountered;
31 // otherwise, it will not retry.
32 // Returns nil if f is nil.
33 func TransientOnly(f Factory) Factory {
34 if f == nil {
35 return nil
36 }
37 return wrap(f, func(it Iterator) Iterator {
38 return &transientOnlyIterator{it}
39 })
40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698