Asynchrony (computer programming): Difference between revisions

Content deleted Content added
Line 17:
 
==Scenarios for Async==
1. '''I/O operations''': Examples are: making a network call, talking to a database, reading a file, printing a document, etc. A synchronous program that performs an I/O operation will come to an halt until the operation finishes. A more efficient program would instead perform the operation and continue executing other code while the operation is pending. Say you have a program that reads some user input, makes some computation and then sends the result via email. When sending an email, you have to send some data out to the network and then ''wait for the receiving server to respond''. Time invested by waiting for the server to respond is time wasted that would be of much better use if the program continued computing.
1. '''I/O operations''': I/O operations like file I/O, network I/O, database I/O, (which is generally just network I/O), and web service calls benefit from asynchrony. Anytime that your code is making a database call, or a web service call or a network call or talking to the file system, that can be done asynchronously while that operation is in progress.
 
2. '''Performing multiple operations in parallel''': When you need to do different operations in parallel, for example, making a database call, web service call and any calculations, then we can use asynchrony.