-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathoptions.go
58 lines (50 loc) · 1.47 KB
/
options.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
52
53
54
55
56
57
58
package rpc
import (
pubsub "github.com/libp2p/go-libp2p-pubsub"
)
// PublishOptions defines options for Publish.
type PublishOptions struct {
ignoreResponse bool
multiResponse bool
republish bool
pubOpts []pubsub.PubOpt
}
var defaultOptions = PublishOptions{
ignoreResponse: false,
multiResponse: false,
republish: false,
}
// PublishOption defines a Publish option.
type PublishOption func(*PublishOptions) error
// WithIgnoreResponse indicates whether or not Publish will wait for a response(s) from the receiver(s).
// Default: disabled.
func WithIgnoreResponse(enable bool) PublishOption {
return func(args *PublishOptions) error {
args.ignoreResponse = enable
return nil
}
}
// WithMultiResponse indicates whether or not Publish will wait for multiple responses before returning.
// Default: disabled.
func WithMultiResponse(enable bool) PublishOption {
return func(args *PublishOptions) error {
args.multiResponse = enable
return nil
}
}
// WithRepublishing indicates whether or not Publish will continue republishing to newly joined peers as long
// as the context hasn't expired or is not canceled.
// Default: disabled.
func WithRepublishing(enable bool) PublishOption {
return func(args *PublishOptions) error {
args.republish = enable
return nil
}
}
// WithPubOpts sets native pubsub.PubOpt options.
func WithPubOpts(opts ...pubsub.PubOpt) PublishOption {
return func(args *PublishOptions) error {
args.pubOpts = opts
return nil
}
}