Skip to content
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

Add StreamAsync alternatives to support IAsyncEnumerable #1692

Closed
wants to merge 10 commits into from

Conversation

dwfrancis
Copy link

Add StreamAsync alternatives to connecton.QueryAsync and gridReader.ReadAsync to support IAsyncEnumerable in a non-breaking way.

Unlike QueryAsync, stream will default to unbuffered.

@dwfrancis
Copy link
Author

Intentionally omitted cancellation tokens to keep the signatures similar.

Since these are new I can include them.

@dwfrancis dwfrancis force-pushed the feature/asyncStreams branch from 5256b4f to 8fbb9b6 Compare November 26, 2021 15:29
@dwfrancis
Copy link
Author

Re-authored commits (forgot to reset git config from a work account)

@dwfrancis
Copy link
Author

dwfrancis commented Jan 3, 2022

Completes the "new IAsyncEnumerable API" task in V2 API refactors #1293

@mgravell
Copy link
Member

mgravell commented Jan 3, 2022 via email

@fdcastel
Copy link

Will review when I'm back at in work-mode.

@mgravell... Are you back from your sabbatical? 😅

@dwfrancis Thanks for the excellent work! I'm using the code in some non-production capacity (going into production next month) and so far it is going smoothly. 👍

@Sonic198
Copy link

Sonic198 commented Sep 9, 2022

I'm also waiting for that :D

@pcooper
Copy link

pcooper commented Sep 9, 2022

I was able to work around lack of support with the current stable version by using ExecuteReaderAsync to get a data reader, then get a row parser from that.

var reader = await connection.ExecuteReaderAsync(sql, param);
var rowParser = reader.GetRowParser<MyType>();
while (await reader.ReadAsync())
{
  var value = rowParser(reader);
  // Do other sync/async stuff with value.
  yield return value;
}

This also worked with dynamic typed row parser funcs.

@Conbag93
Copy link

Just wanted to also add my thanks to @dwfrancis for this PR.
I hope that it gets the offical 'nod' of approval because this has allowed me to experiment with some of the new-ish .net features wiith very minimal code changes.

Combining this with System.Text.Json's newly introduced support for asynchronous Json serialization allows my API to return each row to the client as soon as they are retrieved from the database.
Additionally, if the client also knows the "count" ahead-of-time then I can leverage this to track the progress of a long-running query.

@SoftStoneDevelop
Copy link

It looks like a different implementation of what I did(#1882) as part of the solution #1239 (because in the comments to the issue it was #1239 (comment)).

The fundamental difference is that I rewrote SqlMapper.Async and SqlMapper.GridReader.Async from pseudo-async to IAsyncEnumerable. And of course added "buffered" parameter.
Because my opinion is that there should be either a synchronous method or an asynchronous one. A pseudo-asynchronous wrapper over a synchronous one has no right to exist.

My point is that it might be worth choosing one of these two pull requests or considering them together.

@ronimizy
Copy link

Any updates on that? 👀

@SoftStoneDevelop
Copy link

Any updates on that? 👀

No, Dapper seems to be abandoned.

@mgravell
Copy link
Member

mgravell commented Jun 9, 2023

Dapper is absolutely not abandoned; see #1909 for status; this feature now essentially provided via #1912 - so: I appreciate the input, but I think we should re-address needs when #1912 is in

@mgravell mgravell closed this Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants