You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've recently started using Channels and in my case, there's only one reader so I set SingleReader = true. I also needed to check if the channel is empty using channel.Reader.Count == 0 but I found out that in the single-reader mode, which is implemented by SingleConsumerUnboundedChannel, counting is not supported.
So, I started reading the source code and found that as the channel is using SingleProducerSingleConsumerQueue under the hood and it doesn't support Count publicly because of thread-safety issues, the channel doesn't support it as well.
I know that add support for count requires synchronization for the reader which is in conflict with the purpose of the single-reader mode but isn't it possible to add support for a nonsafe count? Or even add synchronization in the count property?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I've recently started using Channels and in my case, there's only one reader so I set
SingleReader = true
. I also needed to check if the channel is empty usingchannel.Reader.Count == 0
but I found out that in the single-reader mode, which is implemented bySingleConsumerUnboundedChannel
, counting is not supported.So, I started reading the source code and found that as the channel is using
SingleProducerSingleConsumerQueue
under the hood and it doesn't supportCount
publicly because of thread-safety issues, the channel doesn't support it as well.I know that add support for count requires synchronization for the reader which is in conflict with the purpose of the single-reader mode but isn't it possible to add support for a nonsafe count? Or even add synchronization in the count property?
Beta Was this translation helpful? Give feedback.
All reactions