-
Notifications
You must be signed in to change notification settings - Fork 97
Description
Describe the problem you are trying to solve
I am working in a memory-constrained environment, and the data I need to fetch is quite large. For this reason, I am using SearchStreamAsync. My application retrieves the data using SearchStreamAsync and imports it into our database. However, it appears that SearchStreamAsync does not provide an awaitable response callback to insert data into the database asynchronously.
Describe the solution you would like
Currently, SearchStreamAsync accepts an input of type Action. Instead, we could add an overloaded method that takes a Func<SearchGoogleAdsStreamResponse, Task> as input, as shown below:
public virtual Task<SearchStreamStream> SearchStreamAsync(
SearchGoogleAdsStreamRequest request,
Func<SearchGoogleAdsStreamResponse,Task> responseCallback,
CallSettings callSettings = null)
{
SearchStreamStream searchStream = this.SearchStream(request, callSettings);
// Issue a search request.
Task<SearchStreamStream> t = Task.Run(async () =>
{
var responseStream = searchStream.GetResponseStream();
bool emptyResult = true;
while (await responseStream.MoveNextAsync().ConfigureAwait(false))
{
emptyResult = false;
SearchGoogleAdsStreamResponse resp = responseStream.Current;
await responseCallback(resp);
}
// Invoke the callback at least once to avoid confusion when there are no results
// and no errors.
if (emptyResult)
{
await responseCallback(new SearchGoogleAdsStreamResponse());
}
return searchStream;
});
return t;
}
Describe alternatives you've considered
- We can first load all the data into an in-memory collection. However since we have constrained application memory environment that is causing out of memory issues.
Additional context
Add any other context or screenshots about the feature request here.