Skip to content

Server Sent Events implementation #309

Answered by Matasx
Matasx asked this question in Q&A
Aug 28, 2022 · 3 comments · 2 replies
Discussion options

You must be logged in to vote

Ok after a day of struggling I think I have figured out the missing piece.

I implemented this response content:

    public class PushStreamContent : IResponseContent
    {
        private readonly Func<Stream, uint, Task> _writer;

        public PushStreamContent(Func<Stream, uint, Task> writer)
        {
            _writer = writer;
        }

        public ulong? Length => null;

        public ValueTask<ulong?> CalculateChecksumAsync() => ValueTask.FromResult<ulong?>(null);

        public async ValueTask WriteAsync(Stream target, uint bufferSize)
        {
            await _writer(target, bufferSize);
        }
    }

Example usage:

        [ResourceMethod(path: "test")]
        pu…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Kaliumhexacyanoferrat
Comment options

Answer selected by Matasx
Comment options

You must be logged in to vote
1 reply
@Matasx
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants