My friend was moving to Surat, invited me to a party and some shopping. We went to a restaurant. It was Sunday so the restaurant was full. They noted down our names, gave us a token number, and asked us to wait🥺
It was taking so much time so decided to try some other restaurant. Again, no table available BUT their approach was different. They took our contact no and asked to do our shopping work and when a table was available, they would give us a call. A win-win for both.
But soon, we started getting offer discount messages from the restaurant. Oops!!! The next time, we clearly denied to give them our contact no, so they gave us a buzzer which will ring when a table is empty and told us to go shopping. They have nothing from us now, it's up to us that we want to go or not when the buzzer rings.
1 - Synchronous ( Blocking approach ) - Not efficient
2 - Giving contact no means leaving a callback, non-blocking but not that efficient as no control over callback (SPAM MSGS), callback hell (nested callbacks)
3 - async-await (wrapped in promise) - asynchronous, non-blocking, easy and clean, No callback only two args - resolve and reject, efficient but messy error handling