Skip to content

Async Reading Support #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Turnerj opened this issue Apr 17, 2018 · 7 comments · Fixed by #110
Closed

Async Reading Support #26

Turnerj opened this issue Apr 17, 2018 · 7 comments · Fixed by #110
Labels
affects-querying Query-related issue enhancement Enhancements & features moderate-change Moderate changes required
Milestone

Comments

@Turnerj
Copy link
Member

Turnerj commented Apr 17, 2018

Look into support for something like Entity Framework's ToListAsync and how hard that might be to implement in the current stack.

@Turnerj Turnerj added the enhancement Enhancements & features label Apr 17, 2018
@Turnerj Turnerj added this to the Version 1 milestone Apr 17, 2018
@Turnerj
Copy link
Member Author

Turnerj commented Nov 25, 2018

C# Lang Proposal: https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/async-streams.md
Would add async reading once something like async streams land.

@Turnerj Turnerj removed this from the Version 1 milestone Nov 25, 2018
@dongshengfengniaowu
Copy link

The default .net core 3.0 Mvc core ,don't support the none async method. When will MongoFramework support the async query ?

@Turnerj
Copy link
Member Author

Turnerj commented May 28, 2019

Not entirely sure what you mean - it doesn't seem that there is an issue using MongoFramework in ASP.NET Core 3 MVC with MongoFramework being sync-only for reads. Controller actions etc still seem to support sync.

Async reads in general for MongoFramework though, I'm really wanting to have the language proposal come through so I can use the IAsyncEnumerator interface and use foreach async internally. The main part is in places like this: https://github.com/TurnerSoftware/MongoFramework/blob/master/src/MongoFramework/Infrastructure/Linq/MongoFrameworkQueryable.cs#L37-L109

If I don't wait for the IAsyncEnumerator etc myself and just implement something that returns Task<IEnumerable<TEntity>>, while it would be an async query to the database, it means all results would be fetched at once rather than one at a time. If you fetch a lot of results, it means a lot of memory being used at once.

If instead the IAsyncEnumerator is used (when it is released, still a language feature that is coming and will only come to .NET Core 3 as far as I know), then you can asynchronously fetch one item at a time.

I made MongoFramework to help me with my own ASP.Net project and I do want async reads, I just don't think the time is right yet till these building blocks (IAsyncEnumerator and foreach async) are available.

@Turnerj
Copy link
Member Author

Turnerj commented May 28, 2019

Here is a good article of the state of affairs: https://stu.dev/iasyncenumerable-introduction/

Other places have implemented their own enumerator or enumerable interfaces etc and while I could, it would be better spending my time implementing the "real" version when it comes in C#8.

@dongshengfengniaowu
Copy link

Thank you for your patience !

@Turnerj Turnerj added this to the 1.0.0 milestone Jun 29, 2019
@Turnerj Turnerj modified the milestone: 1.0.0 Jul 9, 2019
@Turnerj Turnerj added moderate-change Moderate changes required affects-querying Query-related issue labels Jul 9, 2019
@Turnerj
Copy link
Member Author

Turnerj commented Jul 11, 2019

Thinking a little more about this again, if I do attempt to land an async version without IAsyncEnumerator etc, I will need to dig into how the async path for the ExpressionPlanBuilder works. I still can't wrap it in an IEnumerable at any point because I can't await in an enumerator but to MoveNextAsync (from the IAsyncCursor), I would need to unless I only want to support ToArrayAsync() and ToListAsync().

Because of the more complex expression logic due to the changes for indexing/querying, it will be interesting to see how easily I can still do it given the level of reflection. Maybe this might be a catalyst for #87 to come sooner (though that is still a mighty lot of effort to build).

@Turnerj Turnerj mentioned this issue Nov 4, 2019
9 tasks
@Turnerj
Copy link
Member Author

Turnerj commented May 19, 2020

This would likely be easier to implement once #112 lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-querying Query-related issue enhancement Enhancements & features moderate-change Moderate changes required
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants