With popular software out today like Node.js, Celery, Twisted, and others boasti
ID: 650001 • Letter: W
Question
With popular software out today like Node.js, Celery, Twisted, and others boasting about being asynchronous, what does it mean?
I've gone through the basic Node.js tutorials and written a few Node.js scripts, but still don't feel comfortable with the topic. Please note that I haven't had I had any formal introduction to the topic.
How exactly does asynchronous software work?
What are the pros and cons?
What are callbacks?
Lastly, how does a synchronous web server perform vs. an asynchronous web server?
Explanation / Answer
Wikipedia might be a good place to start with some general concepts and basic information.
This quote from that page sums it up but probably needs a bit of knowledge to fully understand it.
In programming, asynchronous events are those occurring independently of the main program flow. Asynchronous actions are actions executed in a non-blocking scheme, allowing the main program flow to continue processing.
So with synchronous programming the user initiates an action on the program but then has to wait for the operation to complete before being able to do anything else. An example might be saving a file to disk, you can't do anything else until the file is saved.
With asynchronous programming the user initiates an action, but then can carry on doing other work while the operation completes. The program then notifies the user in some way that its finished. An example here might be printing a document. Here you initiate the print then (after some set up) can carry on while the document is sent to the printer. You get some sort of notification that the printing is complete.
Asynchronous applications rely on multithreading or spawning child processes that do the work.
Callbacks are one mechanism where the calling code can do something when the asynchronous operation is complete. You'll register the callback with the long running process in some way then when it completes the code defined by the callback will be executed.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.