Coder Social home page Coder Social logo

Comments (2)

thenameless314159 avatar thenameless314159 commented on June 28, 2024

Hello, I don't think this would stay within the scope of the class since it was made non-generic in order to be usable with different kind of IMessageReader<T> at once.

The solution that you mentionned would require to introduce a new public strongly-typed generic type that may not be necessary since an extension method could be sufficient (user defined or made generic with a static generic protocol store within the bedrock framework, or even a generic interface with static abstract singleton member if we want to use new language features):

namespace MyProtocolNamespace;

public static class MyProtocolExtensions
{
    // suppose we implemented a singleton pattern in our IMessageReader<MyResult> implementation
    public static ValueTask<ProtocolReadResult<MyResult>> ReadAsync(this ProtocolReader reader, CancellationToken token) 
        => reader.ReadAsync(MyMessageReader.Instance, token);
}

In the user-defined case, you could even wrap the ProtocolReadResult<T> on your own readonly struct to reduce verbosity (given that you make the required changes to the extension method):

public readonly struct MyReceiveResult
{
    public required ProtocolReadResult<MyResult> ReadResult { get; init; }
    public MyResult => ReadResult.Message;
    public bool IsCompleted => ReadResult.IsCompleted;
    public bool IsCanceled => ReadResult.IsCanceled;
}

from bedrockframework.

TheVeryStarlk avatar TheVeryStarlk commented on June 28, 2024

Hi, you're completely right, I missed this point. The idea of creating an extension class sounds much better. Thanks!

from bedrockframework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.