Asynchronous Code Is The Code Which Runs Asynchronously In The Background While The Further Code Executes.
Now What Do I Mean By That?
👇
Lets Understand This With A Simple Analogy:
Consider You Are A Cashier At KFC.
Someone Comes And Gives You An Order For 3 Burgers And 2 Large French Fries.
The Burgers Are Not Ready Yet So You Tell The Person To Wait For 5-10 Minutes For His Order To Get Completed
👇
While His Order Gets Completed You Are Not Going To Stop And Wait For It To Get Completed.
Instead You Will Tell Him To Move To The Side And You Will Take The Order Of The Next Person.
👇
This Is Exactly What Happens In Asynchronous Code.
The Compiler Doesn't Wait For The Asynchronous Code To Get Completely Executed, It Instead Puts It In The Background And Executes Further Code.
👇
Why Would You Want To Use Asynchronous Code In Your Program?
Lets Take An Real Life Example.
You Have An Application In Which You Are Requesting Data From An API. Now This Is A Huge Amount Of Data And It Takes 2 Minutes To Return The Complete Data.
👇
Now When The User Is Using Your Application, You Don't Want The Application To Freeze For 2 Minutes While Data Is Returned, Instead You Want It To Further Continue Its Work.
Here's Where You Use Async Code
Now Lets See How To Write An Async Function In Python And Javascript
👇
PYTHON:
JAVASCRIPT :
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Before I Start The Explanation, This Is A Recording Of What The Code Does.
👇
In The 1st Line, We Are Importing Selenium.
@SeleniumHQ Is A Tool Which Helps Us Automate Tasks In Web Browsers. We Can Automatically Click Buttons, Fill Text Fields, Get The Data From Web Page And Many Other Things, All By Code.
"Colab allows anybody to write and execute arbitrary python code through the browser, and is especially well suited to machine learning, data analysis and education."
👇
In Simple Words,
Google Colab Let's You Write Python Code In the Browser And Executes It On Their Cloud CPU, GPU or TPU.
If You Want To Host Your Bot Or Your Dynamic Website Or Any Program, @heroku Is One Of The Best Places To Start, Go Ahead Create An Account And Upload Your Project And Get It Up And Running In Less Than 10 mins. Check Them Out Here -