Closed Jmgr closed 3 years ago
Having given this more thought, I see multiple options on how to present this to the end user.
Connect
function that can be used to cancel the connection and set a timeout to it. This I believe would be the standard Go way, but it would mean changing the API so probably not applied until v3.Connect
function.Also there are two types of connections, the one initiated by the user by calling Connect
, but also other ones directed to the brokers. Do we want to set the same timeout to both, or separately?
I like passing a Context
. What about adding a new function, ConnectCtx
that accepts a Context
to avoid a breaking API change. Then, in v3, we can replace Connect
with ConnectCtx
?
Also there are two types of connections, the one initiated by the user by calling Connect, but also other ones directed to the brokers. Do we want to set the same timeout to both, or separately?
It would probably only make sense to re-use the timeout if it was passed in a Connect
option rather than a Context
? If we pass a Context
to Connect
, do we need a separate option for configuring these "background" connections?
I like passing a
Context
. What about adding a new function,ConnectCtx
that accepts aContext
to avoid a breaking API change. Then, in v3, we can replaceConnect
withConnectCtx
?
Sounds good :+1:
Also there are two types of connections, the one initiated by the user by calling Connect, but also other ones directed to the brokers. Do we want to set the same timeout to both, or separately?
It would probably only make sense to re-use the timeout if it was passed in a
Connect
option rather than aContext
? If we pass aContext
toConnect
, do we need a separate option for configuring these "background" connections?
Good point, probably not needed then.
The current API does not provide a way to cancel a connection while it is in progress. If the server is not reachable the default GRPC timeout applies, which is a few minutes. It could be good for
liftbridge.Connect
to accept a connection timeout.This could be implemented by using
grpc.DialContext
instead ofgrpc.Dial
.