Closed Confuset closed 6 years ago
Fixes #114
Looks good, although if we are going to use Tasks, would it make sense to use BufferBlock<T>
rather than BlockingCollection<T>
? The upside would be that we would be able to release the thread pool thread while waiting for the next stream to clean up. The downside would be that we would be taking a dependency on a new NuGet package (System.Threading.Tasks.Dataflow), although I'm not sure that's really a bad thing since it's a pretty useful official Microsoft package.
hm. I can't really say anything about BlockingCollection
Another option could be to implement something on our own that does what is needed here:
what you think?
I thougt about this a bit more. I think we can simplify this. Since we only have one consumer, we could simply use an AsyncAutoResetEvent and WaitAsync on this until it gets signaled from a different thread. If so do some cleanup and WaitAsync again.
This way we could pretty much stick to the current implementation, do not need to depend on the additional nuget package and wrap that BlockingCollection. We can use this implementation from Stephan Toub himself… https://blogs.msdn.microsoft.com/pfxteam/2012/02/11/building-async-coordination-primitives-part-2-asyncautoresetevent/
It turned out, that we don't really need the BlockingCollection and it can be replaced by a simple Queue and some sync logic around it.
Looks great, thank you!
Added new Project for NetStandard1_1. All sourcecode files are linked into this project from the original Sodium project. The lowest possible .Net Standard was 1.1 since Sodium requires System.Collections.Concurrent which is available only since 1.1. I also had to remove all usages of Thread in StreamListenerManager.cs as this would only be fully available since .Net Standard 2.0 and reimplementation with Tasks is pretty straight forward. I moved the lambdas into named functions because when debugging the name of the method will be available to the debugger. This was done to get close to naming the Thread, like it was before.