-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathquorumcall.go
More file actions
61 lines (57 loc) · 2.11 KB
/
quorumcall.go
File metadata and controls
61 lines (57 loc) · 2.11 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
51
52
53
54
55
56
57
58
59
60
61
package gorums
// QuorumCall performs a quorum call and returns a Responses object
// that provides access to node responses via terminal methods and fluent iteration.
//
// Type parameters:
// - Req: The request message type
// - Resp: The response message type from individual nodes
//
// The opts parameter accepts CallOption values such as Interceptors.
// Interceptors are applied in the order they are provided via Interceptors,
// modifying the clientCtx before the user calls a terminal method.
//
// Note: Messages are not sent to nodes until a terminal method (like Majority, First)
// or iterator method (like Seq) is called, applying any registered request transformations.
// This lazy sending is necessary to allow interceptors to register transformations prior to dispatch.
//
// This function should only be used by generated code.
func QuorumCall[Req, Resp msg](
ctx *ConfigContext,
req Req,
method string,
opts ...CallOption,
) *Responses[Resp] {
return invokeQuorumCall[Req, Resp](ctx, req, method, false, opts...)
}
// QuorumCallStream performs a streaming quorum call and returns a Responses object.
// This is used for correctable stream methods where the server sends multiple responses.
//
// In streaming mode, the response iterator continues indefinitely until the context
// is canceled, allowing the server to send multiple responses over time.
//
// This function should only be used by generated code.
func QuorumCallStream[Req, Resp msg](
ctx *ConfigContext,
req Req,
method string,
opts ...CallOption,
) *Responses[Resp] {
return invokeQuorumCall[Req, Resp](ctx, req, method, true, opts...)
}
// invokeQuorumCall is the internal implementation shared by QuorumCall and QuorumCallStream.
func invokeQuorumCall[Req, Resp msg](
ctx *ConfigContext,
req Req,
method string,
streaming bool,
opts ...CallOption,
) *Responses[Resp] {
callOpts := getCallOptions(E_Quorumcall, opts...)
builder := newClientCtxBuilder[Req, Resp](ctx, req, method)
if streaming {
builder = builder.WithStreaming()
}
clientCtx := builder.Build()
clientCtx.applyInterceptors(callOpts.interceptors)
return NewResponses(clientCtx)
}