Пример #1
0
#pragma warning disable CA1835 // Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync'
    public async ValueTask <object> ReceiveAsync(CancellationToken cancellationToken)
    {
        // Use trick to wait asynchronously until there is something in the stream.
        // This will throw OperationCanceledException if cancellation token signals for cancellation.
        await _stream.ReadAsync(Array.Empty <byte>(), 0, 0, cancellationToken).ConfigureAwait(false);

        // TODO: Improve implementation to not (potentially) block the thread on I/O operation.
        // Buffer the stream asynchronously until Base128 final marker is met.

        return(_protobuf.Deserialize(
                   _stream,
                   fieldNumber => _fieldNumberCache.GetTypeByFieldNumber(fieldNumber)));
    }