示例#1
0
        private async Task StartReceiverReaderAsync()
        {
            try
            {
                ReadResult readResult = default;

                while (!readResult.IsCompleted && !GeneralToken.IsCancellationRequested)
                {
                    GeneralToken.ThrowIfCancellationRequested();

                    readResult = await ReceiverReader.ReadAsync(GeneralToken);

                    var buffer = readResult.Buffer;

                    if (TryParseJsons(buffer, out var jsonPayloads))
                    {
                        foreach (var jsonPayload in jsonPayloads)
                        {
                            await ProcessPayloadAsync(jsonPayload);
                        }
                    }

                    ReceiverReader.AdvanceTo(buffer.End);
                }
            }
            finally
            {
                await ReceiverReader.CompleteAsync();
            }
        }
示例#2
0
        private async Task StartReceiverWriterAsync()
        {
            FlushResult flushResult = default;

            try
            {
                while (!flushResult.IsCompleted && !GeneralToken.IsCancellationRequested)
                {
                    GeneralToken.ThrowIfCancellationRequested();

                    flushResult = await WriteNextMessageAsync(GeneralToken);
                }
            }
            finally
            {
                await ReceiverWriter.CompleteAsync();
            }
        }