mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2024-12-26 23:30:27 +08:00
make UseTransient context option take a reason argument, for consistency with other options
This commit is contained in:
parent
a21b06e646
commit
980a554aa5
@ -71,15 +71,15 @@ func WithDialPeerTimeout(ctx context.Context, timeout time.Duration) context.Con
|
||||
|
||||
// WithUseTransient constructs a new context with an option that instructs the network
|
||||
// that it is acceptable to use a transient connection when opening a new stream.
|
||||
func WithUseTransient(ctx context.Context) context.Context {
|
||||
return context.WithValue(ctx, useTransient, true)
|
||||
func WithUseTransient(ctx context.Context, reason string) context.Context {
|
||||
return context.WithValue(ctx, useTransient, reason)
|
||||
}
|
||||
|
||||
// GetUseTransient returns true if the use transient option is set in the context.
|
||||
func GetUseTransient(ctx context.Context) bool {
|
||||
func GetUseTransient(ctx context.Context) (usetransient bool, reason string) {
|
||||
v := ctx.Value(useTransient)
|
||||
if v != nil {
|
||||
return true
|
||||
return true, v.(string)
|
||||
}
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user