Skip to content

Instantly share code, notes, and snippets.

@sbaldwin24
Last active August 29, 2015 14:06
Show Gist options
  • Save sbaldwin24/879e9cafada940d198cf to your computer and use it in GitHub Desktop.
Save sbaldwin24/879e9cafada940d198cf to your computer and use it in GitHub Desktop.
Asynchronous vs Synchronous Execution
Lets say playing an audio involves three steps:
1. Getting the compressed song from harddisk
2. Decompress the audio.
3. Play the uncompressed audio.
If your audio player does step 1,2,3 sequentially for every song then it is synchronous.
You will have to wait for some time to hear the song till the song actually gets fetched and decompressed.
If your audio player does step 1,2,3 independent of each other, then it is asynchronous.
ie. While playing audio 1 ( step 3), if it fetches audio 3 from harddisk in parallel (step 1)
and it decompresses the audio 2 in parallel. (step 2 ) You will end up in hearing the song without
waiting much for fetch and decompress.
When you execute something synchronously, you wait for it to finish before moving on to another task.
When you execute something asynchronously, you can move on to another task before it finishes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment