<commit_before>using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using Nimbus.Infrastructure.MessageSendersAndReceivers;

namespace Nimbus.Transports.InProcess.MessageSendersAndReceivers
{
    internal class InProcessQueueReceiver : INimbusMessageReceiver
    {
        private readonly string _queuePath;
        private readonly BlockingCollection<NimbusMessage> _messageQueue;
        private CancellationTokenSource _cancellationTokenSource;

        public InProcessQueueReceiver(string queuePath, BlockingCollection<NimbusMessage> messageQueue)
        {
            _queuePath = queuePath;
            _messageQueue = messageQueue;
        }

        public Task Start(Func<NimbusMessage, Task> callback)
        {
            return Task.Run(() =>
                            {
                                _cancellationTokenSource = new CancellationTokenSource();
                                Task.Run(() => ReceiveMessages(callback));
                            });
        }

        public Task Stop()
        {
            return Task.Run(() =>
                            {
                                if (_cancellationTokenSource == null) return;
                                _cancellationTokenSource.Cancel();
                                _cancellationTokenSource = null;
                            });
        }

        private async Task ReceiveMessages(Func<NimbusMessage, Task> callback)
        {
            var cancellationTokenSource = _cancellationTokenSource;
            if (cancellationTokenSource == null) return; // already cancelled

            while (!cancellationTokenSource.IsCancellationRequested)
            {
                try
                {
                    var nimbusMessage = _messageQueue.Take(cancellationTokenSource.Token);
                    await callback(nimbusMessage);
                }
                catch (OperationCanceledException)
                {
                }
            }
        }
    }
}<commit_msg>Added .ToString override to show queue path<commit_after>using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using Nimbus.Infrastructure.MessageSendersAndReceivers;

namespace Nimbus.Transports.InProcess.MessageSendersAndReceivers
{
    internal class InProcessQueueReceiver : INimbusMessageReceiver
    {
        private readonly string _queuePath;
        private readonly BlockingCollection<NimbusMessage> _messageQueue;
        private CancellationTokenSource _cancellationTokenSource;

        public InProcessQueueReceiver(string queuePath, BlockingCollection<NimbusMessage> messageQueue)
        {
            _queuePath = queuePath;
            _messageQueue = messageQueue;
        }

        public override string ToString()
        {
            return _queuePath;
        }

        public Task Start(Func<NimbusMessage, Task> callback)
        {
            return Task.Run(() =>
                            {
                                _cancellationTokenSource = new CancellationTokenSource();
                                Task.Run(() => ReceiveMessages(callback));
                            });
        }

        public Task Stop()
        {
            return Task.Run(() =>
                            {
                                if (_cancellationTokenSource == null) return;
                                _cancellationTokenSource.Cancel();
                                _cancellationTokenSource = null;
                            });
        }

        private async Task ReceiveMessages(Func<NimbusMessage, Task> callback)
        {
            var cancellationTokenSource = _cancellationTokenSource;
            if (cancellationTokenSource == null) return; // already cancelled

            while (!cancellationTokenSource.IsCancellationRequested)
            {
                try
                {
                    var nimbusMessage = _messageQueue.Take(cancellationTokenSource.Token);
                    await callback(nimbusMessage);
                }
                catch (OperationCanceledException)
                {
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.06392045454545454, 'fraction_numerical': 0.0, 'mean_word_length': 1.58094074526573, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3026064', 'n_tokens_mistral': 934, 'n_tokens_neox': 949, 'n_words': 182}