Skip to content

Server Sent Events implementation #309

Closed Answered by Matasx
Matasx asked this question in Q&A
Aug 28, 2022 · 4 comments · 5 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: 4 comments 5 replies

Comment options

Matasx
Aug 30, 2022
Collaborator Author

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

Matasx Aug 30, 2022
Collaborator Author

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Matasx
Comment options

Matasx Oct 31, 2024
Collaborator Author

@Matasx
Comment options

Matasx Oct 31, 2024
Collaborator Author

@Kaliumhexacyanoferrat
Comment options

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