-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcallopts.go
More file actions
50 lines (44 loc) · 1.42 KB
/
callopts.go
File metadata and controls
50 lines (44 loc) · 1.42 KB
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
package gorums
import (
"google.golang.org/protobuf/proto"
)
type callOptions struct {
ignoreErrors bool
interceptors []any // Type-erased interceptors, restored by QuorumCall
}
// CallOption is a function that sets a value in the given callOptions struct
type CallOption func(*callOptions)
func getCallOptions(opts ...CallOption) callOptions {
o := callOptions{
ignoreErrors: false, // default: return error and wait for send completion
}
for _, opt := range opts {
opt(&o)
}
return o
}
// IgnoreErrors ignores send errors from Unicast or Multicast methods and
// returns immediately instead of blocking until the message has been sent.
// By default, Unicast and Multicast methods return an error if the message
// could not be sent or the context was canceled.
func IgnoreErrors() CallOption {
return func(o *callOptions) {
o.ignoreErrors = true
}
}
// Interceptors returns a CallOption that adds quorum call interceptors.
// Interceptors are executed in the order provided, modifying the Responses
// object before the user calls a terminal method.
//
// Example:
//
// resp, err := ReadQC(ctx, req,
// gorums.Interceptors(loggingInterceptor, filterInterceptor),
// ).Majority()
func Interceptors[Req, Resp proto.Message](interceptors ...QuorumInterceptor[Req, Resp]) CallOption {
return func(o *callOptions) {
for _, interceptor := range interceptors {
o.interceptors = append(o.interceptors, interceptor)
}
}
}