-
-
Notifications
You must be signed in to change notification settings - Fork 64
Synchronous StreamPipeReader #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I agree adding a |
I thought about it a bit. public abstract class SyncPipeReader : PipeReader
{
public abstract ReadResult Read();
}
internal sealed class StreamPipeReader : SyncPipeReader
{
// Existing class + new Read() implementation
}
public static class PipeExtensions
{
public SyncPipeReader UseStrictPipeReader(this Stream stream, int sizeHint)
{
return new StreamPipeReader(..);
}
} |
It isn't exposing a concrete class that concerns me. Nerdbank.Streams has already made plenty of them public. It's that .NET now has an API to own the Stream-to-PipeReader operation so I was eager to get out of it to continue focus on adding value to .NET rather than replacing it. I guess another issue is that Maybe what we could do is just make the existing class public, with the addition you're asking for, remove the Obsolete attribute, and call it good. People who want to use it can instantiate it directly rather than going through the extension method whose return type is a |
If you don't want to change the return type, you could add public SyncPipeReader UseSyncPipeReader(..)
{
// .., current implementation
}
public PipeReader UseStrictPipeReader(..) => UseSyncPipeReader(..); That way the existing public API has not changed at all? |
I just found this library and it's fantastic when running on pre-std 2.1 or migrating old code! 😍
In that spirit, would you consider adding
StreamPipeReader.Read
, a non-async version ofReadAsync
?It would significantly help migrating old code and even boost performance sometimes, here's why:
.Wait()
or.Result
.This former makes rewriting existing code quite hard; the latter is considered a bad practice, but it's what many end up doing.
You end up doing async-over-sync, which is not good either. (Combine with 1: sync-over-async-over-sync)
This just hurts perf.
PipeReader
then?Because it still offers great improvements over the Stream API: how it manages buffers (pooling, zero-copying, etc.), how it lets you "rewind" if data is incomplete.
If we give up on
PipeReader
we would end up having to do the buffer management ourselves, which is not the most pleasant idea.Basically copy and rewrite
ReadAsync
with a sync call and every irrelevant bit removed, e.g.CancellationToken
.Only issue I see would be how to expose the API, as the
StreamPipeReader
class is currently internal...Thoughts?
The text was updated successfully, but these errors were encountered: