Possible issues using .Result on LoadAsync?

18 views
Skip to first unread message

Marcelo Volmaro

unread,
Feb 19, 2018, 8:58:34 AM2/19/18
to RavenDB - 2nd generation document database
Hi,
The question above is more specifically target as calling LoadAsync(...).Result over an entity that should be already loaded because I got it from an include, so for example:

Product product = await session
   
.Include("Supplier")
   
.LoadAsync<Product>("products/1");

Supplier supplier = session.LoadAsync<Supplier>(product.Supplier).Result;

Since the Supplier should already be in memory, I don't think that I may get into troubles (after all, I'm not blocking anything), but I just want to be sure. The reason I'm asking is because I can't await where I'm doing that (different paths, not as simple as the example).

Ryan Heath

unread,
Feb 19, 2018, 9:11:11 AM2/19/18
to rav...@googlegroups.com
.Result is a property of Task<T>, its semantics are the same as waiting for the async process to complete.
In others words, yes, you can :)

// Ryan

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcelo Volmaro

unread,
Feb 19, 2018, 9:20:29 AM2/19/18
to RavenDB - 2nd generation document database
Yes, I know, but .Result blocks the execution of the current thread (that's why you have async). Usually, using .Result on async code is bad idea (unless you know that the .Result is already available).
Since I don't know the internals here, maybe there ARE async code that needs to run inside the LoadAsync even if the entity is already in memory (and if that's the case, I will try to avoid using .Result then, but that would require a significant refactory of code).
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Ryan Heath

unread,
Feb 19, 2018, 9:38:27 AM2/19/18
to rav...@googlegroups.com
The current thread is only blocked in the sense that if an async operation has to be performed, the current thread will wait for it.
We know RavenDB will not issue a request for objects that are already loaded into the session.
Thus in that case no async operation will be performed and the current thread will not be 'blocked'.

// Ryan

To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Feb 19, 2018, 2:25:21 PM2/19/18
to ravendb
Yes, confirmed.
The code path explicitly check if the value is already there and will not do any async operation there.
We don't use ValueTask there because it is more common that it _would_ actually do async operation

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Marcelo Volmaro

unread,
Feb 19, 2018, 3:54:19 PM2/19/18
to RavenDB - 2nd generation document database
Perfect. Thanks!
Reply all
Reply to author
Forward
0 new messages