question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IAsyncEnumerable usage and its default `limit` argument

See original GitHub issue

Every occurrence of something like IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync enforces a limit. This is not limited to GetMessagesAsync but perhaps audit log entries as well, etc… Let’s continue talking about GetMessagesAsync as an example though.

This method takes a mandatory argument limit with default value of MaxMessagesPerBatch (=100) which isn’t in line with IAsyncEnumerable and how that would normally be used. Such limit should default to no limit (or in other words int.MaxValue?)

Correct consumption of IAsyncEnumerable would be to execute api calls until complex conditions are satisfied. To get around this one has to hack it up by passing an int.MaxValue instead of leaving it “unlimited,” with its default value (which isn’t “unlimited.”) Simply, leaving “limit” empty implies no limit, it does not imply 100.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
RheaAyasecommented, Apr 25, 2020

It’s not reckless, it’s correct. If the user of the library is an idiot, it’s not your problem. And I never mentioned (I’ve never used any) other libraries.

But hey, take it or leave it ¯\_(ツ)_/¯

1reaction
foxbotcommented, Apr 25, 2020

The meta around Discord’s API is not favorable to infinite paging, and making that the default seems like a reckless decision, especially only in the name of “consistency with other libraries” which has never been a design goal of this one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to stop propagating an asynchronous stream ...
I have a method that accepts an IAsyncEnumerable as argument, and returns also an IAsyncEnumerable . It calls a web method for each...
Read more >
Async Enumerable in C# (Part 3)
By default, Parallel.ForEachAsync will use the processor count of your computer as the default maximum degree of parallelism. This is a sensible ...
Read more >
Async streams in C# – Deep Dive
Implementing an async stream in C#​​ As we have seen, iterating through an IAsyncEnumerable<T> is very similar to iterating through its ...
Read more >
IAsyncEnumerable with yield in C# - Code Maze
Let's learn about IAsyncEnumerable and the way to iterate over an IEnumerable collection asynchronously with the yield keyword.
Read more >
ASP.NET Core Best Practices
By Mike Rousos. This article provides guidelines for maximizing performance and reliability of ASP.NET Core apps.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found