C
C#2y ago
WarChortle

❔ IAsyncEnumerable vs List<T> as parameter in method

I have a method that is overloaded and will take in a List<T> or IAsyncEnumerable. The method will batch requests up to 10 then send them. I am confident the List<T> version is doing what I expect. But I am unsure exactly what to expect with the IAsyncEnumerable
await foreach (var message in messages)
{
var sqsMessage = JObject.Parse(message).ToObject<Message>();

sendMessageBatchRequest.Entries.Add(new SendMessageBatchRequestEntry()
{
Id = sqsMessage?.MessageId,
MessageBody = sqsMessage?.Body,
MessageAttributes = sqsMessage?.MessageAttributes,
});

if (sendMessageBatchRequest.Entries.Count == batchSize)
{
failedMessages.AddRange(await SendMessagesAsync(sendMessageBatchRequest));
sendMessageBatchRequest.Entries.Clear();

if (_request.PublishingDelayInMs != null)
{
await Task.Delay(_request.PublishingDelayInMs.Value);
}
}
}
await foreach (var message in messages)
{
var sqsMessage = JObject.Parse(message).ToObject<Message>();

sendMessageBatchRequest.Entries.Add(new SendMessageBatchRequestEntry()
{
Id = sqsMessage?.MessageId,
MessageBody = sqsMessage?.Body,
MessageAttributes = sqsMessage?.MessageAttributes,
});

if (sendMessageBatchRequest.Entries.Count == batchSize)
{
failedMessages.AddRange(await SendMessagesAsync(sendMessageBatchRequest));
sendMessageBatchRequest.Entries.Clear();

if (_request.PublishingDelayInMs != null)
{
await Task.Delay(_request.PublishingDelayInMs.Value);
}
}
}
The list T method is the same code but with foreach instead of await foreach.
3 Replies
Sossenbinder
Sossenbinder2y ago
I don't quite get the question, where are you still confused exactly?
Djinn
Djinn2y ago
List<T> does the same as AsyncEnumerable version (but asyncEnumerable is async) so, as Sossenbinder said, what r u questioning?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server