Skip to content

Implement SendCloser on gochan.Protocol #738

@dan-j

Description

@dan-j

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions