Is there a simple way to resurrect UnbufferedChannels? #48131
-
Hi lovely .NET team, System.Threading.Channels has Bounded and Unbounded variants. It turns, though, that back in the day there was also an Unbuffered variant, as described in e.g. this old README. It appears that they were removed a bit later on, documented in this issue. For what I am working on at the moment, however, the UnbufferedChannel is the best fit for what I modelling (long story - basically, it'd be ideal if both the sender and receiver synchronise on the exchange). Is there some reasonably simple approach I could take to bring back UnbufferedChannels specifically for what I'm working on? The only likely possibility I can think of is including a version of the System.Threading.Channels namespace with the UnbufferedChannel parts as a project in my overall Solution. I suspect that after this much, time, however, that'll probably not be a trivial task (if it even could work). (If you're wondering, using BoundedChannel with capacity 1 does work reasonably well, but in my particular circumstance an UnbufferedChannel is preferable) Thanks for your time. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi. You could copy out the old code and try to fix it up to meet your needs (the relevant APIs are virtual to enable creating custom channels), but some aspects of the model don't fit well with the concept, which is one of the reasons it was removed. For example, if a writer is only ever using TryWrite and a reader is only ever using TryRead, given the synchronization required they'll never show up as being there at the same time and thus will never successfully rendezvous. Similarly, if for example a reader was in a loop that did WaitToReadAsync and then a TryRead, it will similarly only work if a writer did a write with WriteAsync; if the writer only ever wrote with TryWrite, they wouldn't successfully rendezvous. |
Beta Was this translation helpful? Give feedback.
Hi. You could copy out the old code and try to fix it up to meet your needs (the relevant APIs are virtual to enable creating custom channels), but some aspects of the model don't fit well with the concept, which is one of the reasons it was removed. For example, if a writer is only ever using TryWrite and a reader is only ever using TryRead, given the synchronization required they'll never show up as being there at the same time and thus will never successfully rendezvous. Similarly, if for example a reader was in a loop that did WaitToReadAsync and then a TryRead, it will similarly only work if a writer did a write with WriteAsync; if the writer only ever wrote with TryWrite, they would…