What is the purpose behind Task.Yield() in the .NET client docs?

443 views
Skip to first unread message

Alex D

unread,
Aug 9, 2022, 11:14:45 AM8/9/22
to rabbitmq-users
Hello!

I am about to embark on moving our .NET client library integration from an EventingBasicConsumer to an AsyncEventingBasicConsumer.

In https://www.rabbitmq.com/dotnet-api-guide.html#consuming-async the example has the line "await Task.Yield();" once the message has been acked. From my understanding of .NET, this yield is not needed due to the entire call stack being async. I can't see the benefit of calling it. I was wondering why this had been added in the example? I am happy to be proved wrong about whether it's needed!

Many thanks,
Alex

Luke Bakken

unread,
Aug 10, 2022, 11:23:47 AM8/10/22
to rabbitmq-users
Hi Alex,

In https://www.rabbitmq.com/dotnet-api-guide.html#consuming-async the example has the line "await Task.Yield();" once the message has been acked. From my understanding of .NET, this yield is not needed due to the entire call stack being async

That's just it ... the current .NET client is not truly "async all the way down" so I believe that call is there to prevent lockups or to satisfy the compiler. You can leave it out but I would then suggest doing extensive testing using your expected workload.

Version 7 of the client has been a long time coming but it should by truly async.

Thanks -
Luke 
Reply all
Reply to author
Forward
0 new messages