-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Proposal: ChannelWriter<T>.DroppedWrites counter #32465
Comments
👍 I find the Channels very intriguing but unusable as implemented. I need to know when the channel is full and writes are being blocked/dropped. Even a simple Count property would be a useful step. |
That now exists: #312 |
@stephentoub Thank you! I really did try to look before asking, but I missed it. 😥 |
As an alternative maybe an overload to bool TryWrite(T data, out BoundedChannelFullAction fullAction);
public enum BoundedChannelFullAction {
None, // Channel isn't full yet
Wait, // When BoundedChannelFullMode.Wait was specified, this could actually just be merged into `DroppedWrite` as the return value from `TryWrite` would disambiguate them
DroppedWrite, // When BoundedChannelFullMode.DropWrite was specified
DroppedOldest, // When BoundedChannelFullMode.DropOldest was specified
DroppedNewest // When BoundedChannelFullModel.DropNewest was specified
} Even just writing that out I'm not sure if it's a very nice API, but it would be nice to be able to get some extra info out of the Or, without an public BoundedChannelWriteResult Write(T data);
public bool TryWrite(T data) {
return Write(data) != BoundedChannelWriteResult.Failed;
}
public enum BoundedChannelWriteResult {
Failed,
Written,
DroppedWrite,
DroppedOldest,
DroppedNewest
} |
I don't see any counters on netcore 3.1.4 |
I'm going to close this as a dup of #36522. Such a callback can trivially be used to implement a counter if that's what's needed. Thanks! |
@stephentoub Yep that'll work perfectly, thanks. |
As far as I'm aware, when operating a
BoundedChannel<T>
with aBoundedChannelFullMode
of any of theDrop*
variants there is no way to tell when and how many writes start being dropped. In all cases the call toTryWrite
will succeed and the producer will be none the wiser.It would be nice feature to have a
DroppedWrites
counter (or something that performs a similar function) that increments whenever a channel drops a pending write from the queue. Something like the following:The text was updated successfully, but these errors were encountered: