Repository: Azure/azure-sdk-for-net
File: sdk/eventhub/Azure.Messaging.EventHubs/src/Primitives/EventProcessor.cs (C#)

Code before:
                                                                     CancellationToken cancellationToken)
        {
            // If EventHubProperties has been initialized, return the cached partition IDs
            // synchronously to avoid async state machine allocation on the common path.

            if (EventHubProperties != null)
            {
                return Task.FromResult(EventHubProperties.PartitionIds);
            }

            // If EventHubProperties hasn't been initialized (processor not yet started),
            // fall back to querying the service directly to preserve pre-5.12.0 behavior.

            return ListPartitionIdsFromServiceAsync(connection, cancellationToken);
        }

        /// <summary>
        ///   Queries the Event Hub service for the set of partition identifiers.
        /// </summary>
        ///
        /// <param name="connection">The connection to the Event Hubs namespace to be used for service communication.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <returns>The set of identifiers for the Event Hub partitions.</returns>
        ///
        private async Task<string[]> ListPartitionIdsFromServiceAsync(EventHubConnection connection,
                                                                      CancellationToken cancellationToken)
        {
            var properties = await connection.GetPropertiesAsync(RetryPolicy, cancellationToken).ConfigureAwait(false);
            return properties.PartitionIds;
        }

        /// <summary>
        ///   Allows reporting that a partition was stolen by another event consumer causing ownership
        ///   to be considered relinquished until the next load balancing cycle reconciles it.
        /// </summary>
        ///
        /// <param name="partitionId">The identifier of the partition that was stolen.</param>
        ///
        private void ReportPartitionStolen(string partitionId) => LoadBalancer.ReportPartitionStolen(partitionId);

        /// <summary>
        ///   Signals the <see cref="EventProcessor{TPartition}" /> to begin processing events. Should this method be called while the processor is running, no action is taken.
        /// </summary>
        ///
        /// <param name="async">When <c>true</c>, the method will be executed asynchronously; otherwise, it will execute synchronously.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> instance to signal the request to cancel the start operation.  This won't affect the <see cref="EventProcessor{TPartition}" /> once it starts running.</param>
        ///
        private async Task StartProcessingInternalAsync(bool async,
                                                        CancellationToken cancellationToken)
        {

Review comment (suggestion):
Not sure that I see the value in encapsulating this in a method.  It creates another state machine for what would be a single line of code:

```csharp
return await connection.GetPartitionIdsAsync(RetryPolicy, cancellationToken).ConfigureAwait(false);
```

I think we'd be better off just removing the method and doing the call inline.



Code after:
                                                                           CancellationToken cancellationToken)
        {
            if (EventHubProperties != null)
            {
                return EventHubProperties.PartitionIds;
            }

            // If EventHubProperties hasn't been initialized (processor not yet started),
            // fall back to querying the service directly to preserve pre-5.12.0 behavior.

            return await connection.GetPartitionIdsAsync(RetryPolicy, cancellationToken).ConfigureAwait(false);
        }

        /// <summary>
        ///   Allows reporting that a partition was stolen by another event consumer causing ownership
        ///   to be considered relinquished until the next load balancing cycle reconciles it.
        /// </summary>
        ///
        /// <param name="partitionId">The identifier of the partition that was stolen.</param>
        ///
        private void ReportPartitionStolen(string partitionId) => LoadBalancer.ReportPartitionStolen(partitionId);

        /// <summary>
        ///   Signals the <see cref="EventProcessor{TPartition}" /> to begin processing events. Should this method be called while the processor is running, no action is taken.
        /// </summary>
        ///
        /// <param name="async">When <c>true</c>, the method will be executed asynchronously; otherwise, it will execute synchronously.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> instance to signal the request to cancel the start operation.  This won't affect the <see cref="EventProcessor{TPartition}" /> once it starts running.</param>
        ///
        private async Task StartProcessingInternalAsync(bool async,
                                                        CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested<TaskCanceledException>();
            Logger.EventProcessorStart(Identifier, EventHubName, ConsumerGroup);

            var capturedValidationException = default(Exception);

            try
            {
                // Acquire the semaphore used to synchronize processor starts and stops, respecting
                // the async flag.  When this is held, the state of the processor is stable.

                if (async)
                {
                    await ProcessorRunningGuard.WaitAsync(cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    ProcessorRunningGuard.Wait(cancellationToken);
                }