Skip to content

Buffer IAsyncEnumerable #73898

Answered by TonyValenti
TonyValenti asked this question in Q&A
Aug 13, 2022 · 4 comments · 1 reply
Discussion options

You must be logged in to vote

@gfoidl That wasn't exactly what I wanted but you inspired me toward the answer I was looking for. Here is what I wanted:

public static class AsyncExtensions {
    public static async IAsyncEnumerable<T> Buffer<T>(this IAsyncEnumerable<T> This, int Count) {

        var options = new BoundedChannelOptions(Count)
        {
            SingleReader = true,
            SingleWriter = true,
            AllowSynchronousContinuations = false,
        };

        var chan = System.Threading.Channels.Channel.CreateBounded<T>(options);
        var reader = chan.Reader;
        var writer = chan.Writer;

        var IE = This.GetAsyncEnumerator();

        async Task<bool> FillAsync() {
           …

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

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

Comment options

You must be logged in to vote
0 replies
Answer selected by TonyValenti
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