4 ms·
What's the difference between this and the BlockingCollection<T>? Aside from being async-friendly it looks pretty similar. You can have a bounded collection wit
by dmfowacc 8y ago
What's the difference between this and the BlockingCollection<T>? Aside from being async-friendly it looks pretty similar. You can have a bounded collection with limited size, and completing the writes looks similar too - collection.GetConsumingEnumerable() responds the same way.
- algorithmsRcool 8y agoGood question. BlockingCollection is actually a wrapper around a ConcurrentQueue. It provides some nice things like....blocking so the queue can be used in a producer/consumer manner. Channels does this but has 2 advantages. 1. It is built on the most up-to-date threading primatives (ValueTask) which gives it a perf advantage. 2. It's internal design is very simple and lightweight. BlockingCollection was designed to have swappable guts. Channels are single purpose. The other nice thing is the channels API is really no nonsense super simple to get GREAT performance out of normal async/await. No tuning really needed. I got >300Krps out of a sequence of chained channels with a buffer size of 1.