forked from luno/reflex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
34 lines (28 loc) · 789 Bytes
/
client.go
File metadata and controls
34 lines (28 loc) · 789 Bytes
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
package reflex
import (
"context"
"github.com/luno/reflex/reflexpb"
)
// StreamClientPB defines a common interface for reflex stream gRPC
// generated implementations.
type StreamClientPB interface {
Recv() (*reflexpb.Event, error)
}
// WrapStreamPB wraps a gRPC client's stream method and returns a StreamFunc.
func WrapStreamPB(wrap func(context.Context, *reflexpb.StreamRequest) (
StreamClientPB, error)) StreamFunc {
return func(ctx context.Context, after string, opts ...StreamOption) (StreamClient, error) {
optionspb, err := optsToProto(opts)
if err != nil {
return nil, err
}
cspb, err := wrap(ctx, &reflexpb.StreamRequest{
After: after,
Options: optionspb,
})
if err != nil {
return nil, err
}
return streamClientFromProto(cspb), nil
}
}