Skip to content
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

Implement SendCloser on gochan.Protocol #738

Closed
dan-j opened this issue Nov 16, 2021 · 2 comments
Closed

Implement SendCloser on gochan.Protocol #738

dan-j opened this issue Nov 16, 2021 · 2 comments

Comments

@dan-j
Copy link
Contributor

dan-j commented Nov 16, 2021

I'm using the gochan protocol for some internal processing of events. I've built a series of cloudevents.Client like so:

  1. Client #1 listens on HTTP for events
  2. For each event received on #1 we send to client #2 using a gochan.Protocol sender.
  3. Client #3 is receiving from the same gochan.Protocol used in #2
  4. For each event received on #3 we send to another client #4 which uses HTTP to an external target.

There's currently no way to wait until all events have finished with the current implementation of gochan.Protocol since it doesn't implement protocol.SendCloser.

You can cancel the ctx passed to client.StartReceiver(), but if you have any outstanding messages not yet received the receiver returns io.EOF as expected.

Closing the underlying channel allows StartReceiver() to continue processing all messages until eventually it returns io.EOF due to the channel being closed, and not because ctx was cancelled.

All this involves is changing gochan.Protocol to have an additional method:

func (sr *SendReceiver) Close(ctx context.Context) error {
	return sr.sender.Close(ctx)
}

Is this sensible, or am I missing something?

@n3wscott
Copy link
Member

Sounds good to me, want to make a PR and ping me?

Glad you are getting use out of that implementation!! Let's make it work as you need it!!

@dan-j
Copy link
Contributor Author

dan-j commented Nov 17, 2021

Yeah, I'm using it to expand a single received event into multiple events and getting the benefit of it all being asynchronous; it's quite handy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants