Asynchronous Programming - Reading Assignment

In synchronous functions, tasks or events won’t be executed before the previous task is completed. Contrary to asynchronous functions which can execute many tasks at the same time.

Callback hell is when a main function has more nested functions to run which converts in asynchronous code because it’s waiting until the previous event respond.

In browser, we deal with it with Promises. Jquery enables us to use a promise library to chain callbacks functions and deal with errors.
In server, we can use Fiber’s package to simulate “synchronicity”. It let us write code in synchronous style with synchronous control flow but without been an asynchronous function.

3 Likes
  1. Synchronous functions fall in direct order thus one can’t start until the previous has finished. Whereas asynchronous can be started, put aside, and resumed at a later time while executing other tasks first.

  2. Many levels and sub levels of nested functions that can get pretty complex.

  3. Use promises in JQuery which enables us to chain callbacks and handle errors. Extend the runtime in Node.js. Use Fibers in Meteor.

3 Likes
  1. What is the difference between synchronous and asynchronous functions?

Synchronous task will run JavaScript continuously until its completion, an asynchronous task can be initiated and then put aside until a later date while synchronous task can continue to run.

  1. What is callback hell?

Callback hell are the multilevel nested functions

  1. Which technique can help us solve callback hell?

In the browser, a common pattern to deal with excessive callbacks is to use promises. jQuery ships with a simple built-in promise library that enables us to chain callbacks and deal with errors.

1 Like

Synchronous function are tasks that are blocking JS engine from executing the code until that tasks are finished.

Asynchronous tasks can be initiated and then put aside until later date while JS gets started on the next task on event loop.

We can solve those problems using promises.

1 Like

1- When functions are synchronous the following function is not executed before the initial one, where the asynch waits to be called.

2- A callback hell is when we have more than few callbacks functions to a single function.

3- We can use promises in the function.

1 Like
  1. Synchronous functions are the ones that run one a single thread, meaning that in order for one function to start executing, all the previously invoked functions must have finished their executions. Asynchronous functions are functions that can run in parallel (or concurrently).

  2. The vanilla way of implementing asynchronous functions is to have as the final argument in a function the next function that needs to run asynchronously. Thus if the developer needs to run multiple functions asynchronously the chaining will grow in number significantly which will lead in code that is hard to read, hard to comprehend and difficult to maintain. That is the callback hell.

  3. In the front end we use promises. In Node.js we can extend the runtime with different libraries that let us write in a synchronous function but run the functions asynchronously in the background.

2 Likes
  1. What is the difference between synchronous and asynchronous functions?
  • synchronous/ blocking: pieces of code that must finish running before responding to any events
  • Asynchronous functions: task can be initiated and put aside to handle other functions
  1. What is callback hell?
  • Callback hell: multiple callbacks going at once because of nesting**
  1. Which technique can help us solve callback hell?
  • Promises: common pattern to deal w excessive callbacks.
    • Jquery ships a built-in promise library to chain call-backs and handle errors.
1 Like
  • What is the difference between synchronous and asynchronous functions?
    -Synchronous is when only one piece of code in a function can run at a time.
    -Asynchronous is when more than one piece of the code in a function can run at time.

  • What is callback hell?

    • More levels and sub levels of code stacking on top of each other making it very complex.
  • Which technique can help us solve callback hell?

    • Using promises.
2 Likes
  1. Asynchronous functions do not block a program and Synchronous functions do.

  2. Callback hell is when a code has many callbacks and is unnecessary and can cause issues.

  3. A common pattern to deal with excessive callbacks is Promises.

1 Like

1)What is the difference between synchronous and asynchronous functions?
Synchronous, you can only execute one thing at the time. While, Asynchronous you can execute multiple things at a time and you don’t have to finish executing the current thing in order to move on to the next one.

2)What is callback hell?
Callback hell is a phenomenon that afflicts JavaScript developer when trying to execute multiple asynchronous operations one after the other. By nesting callbacks in such a way, we easily end up with error prone, hard to read and hard to maintain code.

3)Which technique can help us solve callback hell?
Promise can solve callback hell situation.

2 Likes
  1. What is the difference between synchronous and asynchronous functions?

Synchronous function runs only one section of code at any one time. Tasks are executed one at a time( example by a click function) , and the next task requires the user to click once more( if using another click function) so that the next task is executed. And the browser won’t respond to any events whatsoever while it completes the first action.

Asynchronous functions can be initiated and tasks can be put aside until a later timing, while the browser can get the next task done on the to do list, during the waiting

In JS, the browser’s to-do list is called the event loop. Though the browser can still only do one task at a time, it does not need to wait till task 1 is completed before it executes the subsequent tasks. Hence, The flow is continuous in asynchronous functions because the JavaScript engine actually sports an additional background thread which takes care of managing the event loop.

  1. What is callback hell?

A straight forward request to record each user’s log in to the database would require a three nested functions program, one function being the main function that nests the whole operation, second to look up user in the data base, and third one to record the user log in data.

A more complex request could require many more functions, example, 1 main function, with 30 more sub functions to do many different tasks. The subsequent functions after the main function are called callbacks. When the complexity is multiplied due to huge number of call backs required , it is known as call back hell.

3. Which technique can help us solve callback hell?

In the browser, a common pattern to deal with excessive callbacks is to use promises . jQuery ships with a simple built-in promise library that enables us to chain callbacks and deal with errors.

2 Likes
  1. synchronous: only one event handler after another can be active. In other words, the first event handler has to be completed before the second one can run, and so on.
    asynchronous: while waiting for an event handler to complete we can run others

  2. a high complexity caused by functions being nested in other functions is called callback hell.

  3. there is a “promise library” in jquery that can be used in order to chain callbacks (and to make the code more readable)

2 Likes
  1. Synchronous functions are tasks or processes that occupy JavaScript’s full attention and blocks other processes until that tasks is complete. Asynchronous functions are tasks that can be initiated and while waiting for a response, JS can move to new tasks at hand.

  2. Callback hell occurs when there are excessive callbacks in nested functions (functions within functions within functions and so on) that makes the process complex in order to perform a single or simple task.

  3. In the browser, a technique that helps in solving callback hells is by using promises. jQuery has a simple built-in promise library that enables programmers to chain callbacks and deal with errors that occur.

1 Like
  1. synchronous functions needs to be executed one after onother there slowing down the program.With asynchronous there can be w to do list and the program can do different tasks waiting for another to load
  2. when you have alot of nested functions in a script
  3. by using promises instead
1 Like

1. What is the difference between synchronous and asynchronous functions?
Synchronous functions are those that are ‘blocking’ that is to say that they occupy the Javascript engine until their execution is finished. Asynchronous function on the other hand do not block the Javascript thread, instead they wait for execution to complete while the thread does other work.
2. What is callback hell?
Nested event handlers allow our code to become asynchronous, but can leave our code open to becoming overly complex and difficult to read.
3. Which technique can help us solve callback hell?
Promises can be used to write asynchronous code that still appears as though it is executing in a top-down way.

1 Like
  1. What is the difference between synchronous and asynchronous functions?
  • Synchronous functions block occupy javascript engine till the job is done . In other hand we have Asynchronous functions which do not block the program and wait while the program thread does other task.
  1. What is callback hell?
  • Callback hell is a situation where several functions are being performed in nested form.
  1. Which technique can help us solve callback hell?
  • Apparently “promises” help to deal with a lot of callbacks, though Node.js provides a different approach “to abstract away the asynchronicity and write code that looks synchronous.”
1 Like

Q1: What is the difference between synchronous and asynchronous functions?
A1: Synchronous functions occur sequentially one after the other and each only begins to execute after the previous one has been completed. Asynchronous functions on the other hand, allow other functions to begin before another has completed.

Q2: What is callback hell?
A2: An undesirable situation where several nested callback functions are needed in order to perform relatively simple tasks making code harder to write and maintain.

Q3: Which technique can help us solve callback hell?
A3: Promises in the browser using jQuery and/or async await on the server with Node.js

1 Like
  1. What is the difference between synchronous and asynchronous functions?

Synchronous functions are functions that block any other events from executing while they themselves are executing. These come into existence due to JS’s single-threaded design. Asynchronous functions by contrast initiate an asynchronous task, and begin executing the next events/code while they themselves are executing in a background thread.

  1. What is callback hell?

Callback hell occurs when various nested functions wait for a callback i.e. the value of an argument yielded from the execution of another nested function. This can lead to significant lag time in the execution of even simple tasks, and becomes a substantial issue when code is complex.

  1. Which technique can help us solve callback hell?

Promises are frequently employed to combat callback hell. Different applications provide different built-in promise libraries for this purpose, allowing developers to chain callbacks and handle errors. Without the use of libraries, the issue can also be solved by extending the runtime, abstracting away asynchronicity and writing code with synchronous control flow (e.g. in node.js).

1 Like
  1. What is the difference between synchronous and asynchronous functions?

Synchronous functions can run one at a time in specific order while asynchronous functions can run out of the order that it is written in the code.

  1. What is callback hell?

When nested functions become painfully complex to manage and debug.

  1. Which technique can help us solve callback hell?

Promises under jQuery which ships with a simple built-in promise library that enables you to chain callbacks and deal with errors.

1 Like

1.synchronous functions are executing one by on, so it is blocking any other actions until function is executed, asynchronously can be in process while other functions are running
2. callback hell is a huge amount of sub-functions
3.The simplest way to use Fibers

1 Like