17 using System.Threading;
19 using System.Collections.Generic;
28 private readonly Action<T> _processMessages;
29 private readonly Queue<T> _messageBuffer;
30 private readonly
object _streamLocked;
38 _processMessages = processMessages;
39 _messageBuffer =
new Queue<T>();
40 _streamLocked =
new object();
51 if (Monitor.TryEnter(_streamLocked))
55 ProcessMessages(message);
59 Monitor.Exit(_streamLocked);
64 if (message !=
default)
68 _messageBuffer.Enqueue(message);
79 Monitor.Enter(_streamLocked);
92 Monitor.Exit(_streamLocked);
102 private void ProcessMessages(T message =
null)
107 while (_messageBuffer.TryDequeue(out var e))
114 _processMessages(message);