Projects with synchronous and asynchronous APIs

1

I'm developing a small project and I have two entities for now:

  • Product and Customer

The product API is asynchronous (with Task and async) and the client API is synchronous.

I wonder if there is any problem in using these two approaches in the same project? What problems, if any?

Another question is also when it is really recommended to use asynchronous APIs in projects?

    
asked by anonymous 07.08.2018 / 13:46

1 answer

4

In principle no problem. Of course, the moment they interrelate the synchronous will always prevail and the synchronous stop will cause wait at that point, but if it is within something being called asynchronously that part will still maintain competition. If you synchronously call a code in an asynchronous method this call will be synchronous, and only one call to this calling method will be asynchronous, which may not be relevant.

Remember that async is useful for IO, so the last case I mentioned should have no advantage under normal conditions. The IO operation has to be originally asynchronous in order to have gains. If the execution is very fast it does not pay to use such a heavy mechanism. It establishes the minimum of 50ms of execution time (it is not cake recipe), which is relatively rare to have operations like this. Only with large volumes or some very slow IO will gain.

In processing you gain concurrency or even parallelism with thread and not with async .

I answered in more detail in other questions:

07.08.2018 / 16:08