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

Allow Configuration of Subscription Channels #93

Merged
merged 1 commit into from
Jul 23, 2023

Conversation

to11mtm
Copy link
Collaborator

@to11mtm to11mtm commented Jul 18, 2023

There is value in being able to configure the BoundedChannelOptions for a given subscription (or series of subscriptions.)

For example, in cases where it is preferred to discard older data on a subscription, or cases where only the most recent value is the one that is desired.

This PR also has the benefit, in the default case, we can just re-use our internal BoundedChannelOptions rather than passing a new one every time a new subscription is created (i.e. less memory allocation.)

Note that for the sake of reuse, this marked internal static on NatsSub rather than private static, since to have a separate static readonly on NatsSub<T> would both be unnecessary and would cause a new static to be allocated for every new T on NatsSub<T>.

@mtmk mtmk linked an issue Jul 19, 2023 that may be closed by this pull request
@to11mtm to11mtm force-pushed the allow-channel-configuration branch from e49da81 to 0ba3142 Compare July 21, 2023 20:34
{
var overrideOpts = subChannelOpts.Value;
return new BoundedChannelOptions(overrideOpts.Capacity ??
DefaultChannelOptions.Capacity)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seemed better from a maintenance perspective to fallback to DefaultChannelOptions rather than re-specify defaults for these. If preferred I can just re-specify defaults however.

@@ -55,7 +55,7 @@ public abstract class NatsSubBase : INatsSub
_cts.Token.UnsafeRegister(
static (self, _) =>
{
((NatsSubBase) self!).EndSubscription(NatsSubEndReason.Cancelled);
((NatsSubBase)self!).EndSubscription(NatsSubEndReason.Cancelled);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Linter complained about this so I went ahead and did it. If revert is preferred LMK.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Make sure to run dotnet format. That should fix these issues as well.

@@ -1,3 +1,5 @@
using System.Threading.Channels;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this using came in because of the XmlDoc, if preferred I can just use full type name in xmldoc?

@mtmk
Copy link
Collaborator

mtmk commented Jul 21, 2023

@to11mtm couls you rebase please? There are no conflicts but it'd be easier to see without warnings etc. which was fixed afterwards.

@to11mtm to11mtm force-pushed the allow-channel-configuration branch from 0ba3142 to 216583a Compare July 22, 2023 01:15
@to11mtm to11mtm force-pushed the allow-channel-configuration branch from 216583a to 33538dd Compare July 23, 2023 13:38
Copy link
Collaborator

@mtmk mtmk left a comment

Choose a reason for hiding this comment

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

LGTM

@mtmk mtmk merged commit e13213e into nats-io:main Jul 23, 2023
4 checks passed
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.

Allow Configuration of the BoundedChannel used for a subscription
2 participants