这是indexloc提供的服务,不要输入任何密码
Skip to content

SearchStreamAsync is missing asynchronous response callback #622

@ashish-bhagwani

Description

@ashish-bhagwani

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions