Skip to content

Instantly share code, notes, and snippets.

@brnls
brnls / Time Buffered Channel Reader.md
Last active January 26, 2024 03:27
Time Buffered Channel Reader
public class BufferedChannel<T>
{
    private readonly Channel<T> _input;
    private readonly Channel<IReadOnlyCollection<T>> _output;

    public BufferedChannel(TimeSpan time, int maxItems)
    {
        _input = Channel.CreateBounded<T>(maxItems);
        _output = Channel.CreateBounded<IReadOnlyCollection<T>>(1);
@brnls
brnls / Concurrent Consumer.cs
Created September 22, 2023 03:41
Concurrent Consumer
using System.Threading.Channels;
using Confluent.Kafka;
using Microsoft.Extensions.Logging;
namespace Worker1;
public delegate Task MessageHandler(ConsumeResult<string, byte[]> result, Action acknowledge, CancellationToken cancellationToken);
public class ConcurrentKafkaReceiver : IAsyncDisposable
{