News for hackers. Stuff that matters.
Re:Announcing .NET Core 2.1 by quickthrower2 on Wednesday May 30, 2018 @02:54PM (#17190551)
Where can I find out more about Channel<T>? I've been googling but it's hard to find anything (especially as Channel 9, and old WCF channels comes up a lot in the results).
Re:Announcing .NET Core 2.1 by algorithmsRcool on Wednesday May 30, 2018 @03:26PM (#17190877)
The Docs on Channel<T> are currently lacking :(

But it is pretty simple to use. It is in nuget package "System.Threading.Channels".

You basically call Channel.CreateBounded<T>(int) to create a channel that will buffer a limited number of T objects.

A Channel has a ChannelReader and ChannelWriter which are two ends of the same channel. The reader is the output side, the writer is the input side.

Each side exposes methods to synchronously try to Read or Write or asynchronously Read or Write (respectively).

It supports "Completion" meaning that the Writer can signal the Reader(s) that it is done writing forever. For example imagine you had a channel that was for Log Messages. A bunch of readers might be listening, but then the App shuts down. The writer can call "Complete()" on the channel and the Readers will get wake up and get a message that there is no more messages and flush themselves and shut down.

As a note you will need to run your own processing thread to await messages from the channel. Unlike Dataflow which will span it's own taks to handle messages.

I will write up an example Gist and reply to this thread in a little bit.

Other notes: - The API is very similar to Dataflow since Stephen Toub wrote them both. - It is extremely fast. I have seen > 1.25M messages per second in my benchmarks. - It is mostly allocation free due to using the new ValueTask<T> which is a struct

Futher Reading: https://www.nuget.org/packages/System.Threading.Channels/ https://apisof.net/catalog/System.Threading.Channels

Re:Announcing .NET Core 2.1 by algorithmsRcool on Wednesday May 30, 2018 @04:04PM (#17191264)
Here is the example code. Comments and Questions are welcome.

https://gist.github.com/AlgorithmsAreCool/b0960ce8a3400305e4...

Re:Announcing .NET Core 2.1 by dmfowacc on Wednesday May 30, 2018 @06:05PM (#17192313)
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.
Re:Announcing .NET Core 2.1 by algorithmsRcool on Wednesday May 30, 2018 @09:26PM (#17193280)
Good 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.

Re:Announcing .NET Core 2.1 by quickthrower2 on Friday June 01, 2018 @04:29PM (#17209867)
Thanks.

This sounds very similar to the channels (Chan [1]) in Haskell, which I really loved playing around with.

[1] http://hackage.haskell.org/package/base-4.11.1.0/docs/Contro...

Re:Announcing .NET Core 2.1 by manigandham on Monday June 04, 2018 @06:57AM (#17226546)
There is this readme in the original Channel<T> Stephen Toub's branch: https://github.com/stephentoub/corefxlab/blob/master/src/Sys...
Re:Announcing .NET Core 2.1 by oaiey on Wednesday May 30, 2018 @03:21PM (#17190814)
Channel was an early prototype name of System.IO.Pipelines. see https://github.com/davidfowl/Channels
Re:Announcing .NET Core 2.1 by algorithmsRcool on Wednesday May 30, 2018 @03:26PM (#17190891)
Yes, but the Channel<T> i am referring to is a separate project from Stephen Toub that came from CoreFxLab
Re:Announcing .NET Core 2.1 by oaiey on Wednesday May 30, 2018 @03:42PM (#17191049)
Damn. Naming is hard right :)
Re:Announcing .NET Core 2.1 by ihsw2 on Wednesday May 30, 2018 @03:03PM (#17190662)
The closest analogue is probably `ConcurrentQueue<T>`.

https://msdn.microsoft.com/en-us/library/dd267265(v=vs.110)....

Re:Announcing .NET Core 2.1 by oaiey on Wednesday May 30, 2018 @03:22PM (#17190824)
Nope. Not the same. System.IO.Pipelines is final name of Channels
Re:Announcing .NET Core 2.1 by oaiey on Wednesday May 30, 2018 @03:43PM (#17191056)
I stand corrected. See other replies.