0

I am saving documents to a CosmosDB and both the below works, Can someone please explain what the difference is? I see no performance difference and really cannot see any difference at all when running the code.

Is one going to be faster than the other when the number of documents increases?

docClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, databaseCollection), JObject.Parse(singleItem))
                            .GetAwaiter().GetResult();

await docClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, databaseCollection), JObject.Parse(singleItem));
Matt Douhan
  • 2,053
  • 1
  • 21
  • 40
  • 1
    Your question seems to boil down to using async/await vs calling synchronously. Perhaps read this as a starting point: https://stackoverflow.com/questions/23871806/async-await-performance and https://stackoverflow.com/questions/34549641/async-await-vs-getawaiter-getresult-and-callback – Dean Goodman Aug 14 '19 at 14:39

1 Answers1

0

It has nothing to do with CosmosDB, in C# programing The async and await keywords are used in async programming.

Anyway the difference between those two are,

docClient.CreateDocumentAsync 

This one acts as a fire and forget way, it will not wait till the record gets created and there will not be any response received. You would not know even if the document has been created or not.

whereas,

await docClient.CreateDocumentAsyn

Wait till the document gets created and response code recieved.

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396