internal void AddSend <T>(Channel <T> channel, object msg) { if (_channelOperations.Any(co => co.Channel == channel)) { throw new InvalidOperationException("Channel has been already registered in an other case"); } var sendChannelOperation = new SendChannelOperation(channel, _evt, msg); _channelOperations.Add(sendChannelOperation); }
protected async Task <bool> SendCoreAsync(object msg) { if (_isClosed) { throw new ChannelClosedException(); } Lock(); if (_readerQueue.TryDequeue(out TransferQueueItem readerQueueItem)) { Unlock(); readerQueueItem.ChannelOperation.Msg = msg; readerQueueItem.ChannelOperation.Notify(); return(true); } if (IsBuffered && _msgQueue.Count < _queueSize) { _msgQueue.Enqueue(msg); Unlock(); return(true); } var evt = new CompletionEvent(); var sendOperation = new SendChannelOperation(this, evt, msg); _writerQueue.Enqueue(new TransferQueueItem(sendOperation)); Unlock(); await evt.WaitAsync(); if (_isClosed) { throw new ChannelClosedException(); } return(true); }
internal bool SendFast(SendChannelOperation sendChannelOperation, Action unlock) { if (_readerQueue.TryDequeue(out TransferQueueItem readerQueueItem)) { unlock(); readerQueueItem.ChannelOperation.Msg = sendChannelOperation.Msg; readerQueueItem.ChannelOperation.Notify(); return(true); } if (IsBuffered && _msgQueue.Count < _queueSize) { _msgQueue.Enqueue(sendChannelOperation.Msg); unlock(); return(true); } return(false); }