I have an API that returns a list of shops from my database along with shops from Google Places API.
IEnumerable<ShopInOfferDetails> modelApi = null;
IEnumerable<ShopInOfferDetails> modelDb = null;
await new TaskFactory()
.StartNew(() =>
{
modelApi = Service.GetShopsFromGoogleApi(g);
})
.ContinueWith(x =>
{
modelDb = Service.GetShopsFromDb(g);
});
var model = modelApi.Concat(modelDb);
return model;
The thing is that it takes too long to get and process the results from Google API (I am doing some more work at the background) and I wonder if there is a way to get the first data from my database - to return this data to the client and only then to get more data from Google Api and Return again - in such way the client gets the first result fast and then the rest from Google API.
HttpClientand many ORMs. Then you couldawait Task.WhenAllon both. Alternatively, @Damir's suggestion for creating two different calls may also work if you want to show the end user a result ASAP.