-
Notifications
You must be signed in to change notification settings - Fork 0
/
deprecated.go
51 lines (47 loc) · 1.53 KB
/
deprecated.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package breaker
import "context"
// MultiplexTwo combines two breakers into one.
//
// interrupter := breaker.MultiplexTwo(
// breaker.BreakByContext(req.Context()),
// breaker.BreakBySignal(os.Interrupt),
// )
// defer interrupter.Close()
//
// background.Job().Do(interrupter)
//
// Deprecated: Multiplex has the same optimization under the hood now.
// It will be removed at v2.
func MultiplexTwo(one, two Interface) Interface {
return newMultiplexedBreaker([]Interface{one, two, stub{}}).trigger()
}
// MultiplexThree combines three breakers into one.
// It's an optimized version of a more generic Multiplex.
//
// interrupter := breaker.MultiplexThree(
// breaker.BreakByContext(req.Context()),
// breaker.BreakBySignal(os.Interrupt),
// breaker.BreakByTimeout(time.Minute),
// )
// defer interrupter.Close()
//
// background.Job().Do(interrupter)
//
// Deprecated: Multiplex has the same optimization under the hood now.
// It will be removed at v2.
func MultiplexThree(one, two, three Interface) Interface {
return newMultiplexedBreaker([]Interface{one, two, three}).trigger()
}
// WithContext returns a new breaker and an associated Context based on the passed one.
//
// interrupter, ctx := breaker.WithContext(req.Context())
// defer interrupter.Close()
//
// background.Job().Run(ctx)
//
// Deprecated: use BreakByContext instead.
// It will be removed at v2.
func WithContext(ctx context.Context) (Interface, context.Context) {
ctx, cancel := context.WithCancel(ctx)
return (&contextBreaker{ctx, cancel}).trigger(), ctx
}