Example #1
0
        private async ValueTask WriteInternal(WrappedMessage <TOutbound> message, PooledValueTaskSource <MessageId> source)
        {
            try
            {
                await this.writer.WriteAsync <WrappedMessage <TOutbound> >(this.wrappedWriter, message);

                source.SetResult(message.Id);
            }
            catch (Exception ex)
            {
                source.SetException(ex);
            }
        }
Example #2
0
 public Work(WrappedMessage <T> message, Func <WrappedMessage <T>, PooledValueTaskSource <MessageId>, ValueTask> action, PooledValueTaskSource <MessageId> source)
 {
     this.Message = message;
     this.Action  = action;
     this.source  = source;
 }
Example #3
0
        public void Schedule(Func <WrappedMessage <TOutbound>, PooledValueTaskSource <MessageId>, ValueTask> action, WrappedMessage <TOutbound> message, PooledValueTaskSource <MessageId> source)
        {
            workItems.Enqueue(new Work <TOutbound>(message, action, source));

            // Set working if it wasn't (via atomic Interlocked).
            if (Interlocked.CompareExchange(ref doingWork, 1, 0) == 0)
            {
                // Wasn't working, schedule.
                // have to schedule to threadpool to avoid sync path block in Func<object?,ValueTask>
                System.Threading.ThreadPool.UnsafeQueueUserWorkItem(this, preferLocal: false);
            }
        }