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

Musings towards SubscribeNotification for Connection #42

Closed
wants to merge 1 commit into from

Conversation

edwarnicke
Copy link
Contributor

Signed-off-by: Ed Warnicke hagbard@gmail.com

Signed-off-by: Ed Warnicke <hagbard@gmail.com>
@edwarnicke
Copy link
Contributor Author

Note: This PR is mostly meant to be a conversation starter on how we get to being able to subscribe to connections without needing things like: #36

// bufferSize is used to set the buffer size of the go channel returned. If the channel's
// buffer is full, the notifications will not be delivered into it. When the provided ctx is 'Done'
// the return go channel will be closed and no further notifications will be deli
SubscribeNotification(ctx context.Context, event Message, bufferSize int) (chan Message, error)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on design decisions here.

I started with just moving the

SubscribeNotification(notifChan chan Message, event Message) (SubscriptionCtx, error)

from Channel up to Connection. As I was implementing I realized a few places for improvment:

First, everything at Connection Level uses a context.Context, so I added that:

SubscribeNotification(ctx context.Context, notifChan chan Message, event Message) (SubscriptionCtx, error)

Which led me to wanting to clean up the notifChan when the ctx.Done() was closed. Normal Go lang idioms around channels are that the writer owns them and is responsible for closing them. So normally since the Connection is writing to them, it would create and return the channel.

Looking at the code it was clear the reason for the channel being passed in was to control the bufferSize. I can absolutely see why controlling the bufferSize from outside is important.

So I evolved it to:

SubscribeNotification(ctx context.Context, event Message, bufferSize int) (chan Message, error)

@ondrej-fabry ondrej-fabry linked an issue Sep 12, 2022 that may be closed by this pull request
@ondrej-fabry ondrej-fabry marked this pull request as draft October 12, 2022 08:15
@ondrej-fabry
Copy link
Member

Superseded by #80

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

Successfully merging this pull request may close these issues.

None yet

2 participants