-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Braindump] Proposal for redesigning the client interface #607
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Francesco Guardiani <[email protected]>
Signed-off-by: Francesco Guardiani <[email protected]>
// * func(event.Event) (*event.Event, protocol.Result) | ||
// * func(context.Context, event.Event) *event.Event | ||
// * func(context.Context, event.Event) (*event.Event, protocol.Result) | ||
StartReceiver(ctx context.Context, fn interface{}) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about leaving StartReceiver and also add the blocking single pulling functions?
you still need a hook on client to give it a thread, I am not seeing how that is happening without dramatically changing the contract.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about leaving StartReceiver and also add the blocking single pulling functions?
So one of the points with this proposal is that I would love to relax this assumption on the protocol side https://github.com/cloudevents/sdk-go/pull/606/files#diff-484d929efc01852c00d94e8e519500757204bacd6a67224c50db3c805eabc8f5R12 and enforce only in StartReceiver
, where it really matters. Nor StartReceiver
or invoking from multiple threads Receive
makes sense in the context of Websockets.
My worry is that, If we put everything in Client
, we'll have races everywhere, because we need to handle a lot of different cases:
- user invokes Receive, it's blocked on Receive but then invokes StartReceiver
- user invokes StartReceiver, then invokes Receive
- OpenInbound for StartReceiver, then user invokes Receive too
- StartReceiver context is canceled, but then user invokes Receive
While, if we make it clear that StartReceiver
is like one level up/different to the client, e.g. accepting directly the Protocol
in StartReceiver
, then we have a clean implementation, both for StartReceiver
and for Client.Receive
. And also makes pretty clear to the user the usage aka don't mess up with Receive
and StartReceiver
at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe want you are saying is we need a new implementation for a stream based client. Client is for more like pub/sub style apis, and we can create a new one specific for streams like WS provides?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty much, but in particular my point is that I see the pub/sub APIs as a layer on top of a stream API (in fact, protocol APIs are already stream apis)
Think about a v3? |
Maybe, let's get the 2.4 out first 😄 |
Would someone like to follow through on this one? If not we're probably going to close it. |
I came out with this proposal after working on #606.
My problem with the
Client
interface is that, whileSend
andRequest
maps the interfaces in protocol,StartReceiver
doesn't map the semantics ofReceiver
andResponder
. This is particularly weird withwebsocket
for example, when you have a bi-directional client per stream, so you can do something like:In particular, I find that
StartReceiver
is opinionated, maps to the concepts of http more than the concepts of messaging and it's less golang idiomatic than a channel or a method likeReceive
. Another point to consider is that going from the method invocation to the handler mode is relatively straightforward (and we could easily provide the method to do it, like showed in this PR), while going from the handler mode to the method invocation is harder and, generally, more error prone.Signed-off-by: Francesco Guardiani [email protected]