Asynchronous Programming - Reading Assignment

Welcome to the discussion about the reading assignment about asynchronous programming.

Leave your answers to the questions below in this thread. If you have any questions or you want to discuss something connected to the assignment feel free to do it in this thread as well, but please everything to the topic.

  1. What is the difference between synchronous and asynchronous functions?
  2. What is callback hell?
  3. Which technique can help us solve callback hell?
27 Likes
  1. 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. Callback hell is an undesirable situation whereby several nested callback functions are needed in order to perform relatively simple tasks. This makes our code harder to write, debug and maintain.

  3. We can use promises to solve the problem of call back hell. Promises help us to deal with chained synchronous functions and allows us to also handle errors. Modern javascript libraries and frameworks like Angular and jQuery come with a promise library. Another way of dealing with callback hell in Node.js is to extend the runtime and and abstract away the asynchronicity so as to allow the programmer to write asynchronous code in a synchronous style.

16 Likes

1- Synchronous functions block the program’s further execution until something is done while Asynchronous functions do not block the program and wait while the program thread does other task.
2- Callback hell is a situation where several functions are being performed in nested form.
3- Promise is used to solve the call back hell situation. jQuery, AngularJS come with promise library. It also handles errors.

3 Likes
  1. What is the difference between synchronous and asynchronous functions?
  • Synchronous functions - Only one section of the code in the function can run at any one time.
  • Asynchronous functions - More than one section of the code in the function can run at any one time.


    Driving down a road then stopping the car to eat your sandwich but only continuing to drive once you eat your sandwich is synchronous driving.
    Driving down a road eating a sandwich is asynchronous driving.
  1. What is callback hell?

    Basically arguments, within arguments, within arguments, within arguments all waiting for one argument to callback to the other just to start another. Such negativity :slight_smile:

  2. Which technique can help us solve callback hell?

    Different applications use different libraries to help us solve callback hell.
12 Likes
  1. synchronous functions block the program execution until they are finished, while asynchronous functions permit multitasking, in the sense that they send the request and free the program execution until they are called back
  2. Callbacks within callbacks, within callbacks to a degree when maintaining and reading a program becomes messy.
  3. The use of Promises can solve a callback hell situation
2 Likes

1. What is the difference between synchronous and asynchronous functions?
Synchronous functions occur one after the other and don’t allow the next function to begin executing until the previous one has finished.
Asynchronous functions on the other hand will allow other functions to begin before it has completed all of its tasks. For instance, if a function needs to wait for a server to respond, it will happily begin executing the next function and continue with the previous one when the response comes through.

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?
There are a few options to help us deal with callback hell. One being the use of promises, which enables us to chain callbacks and deal with errors.

3 Likes
  1. Asynchronous can be initiated and put aside until later while our main thread gets started on the next task on the to-do list
  2. This is caused when the code includes many callbacks within callbacks and so on.
  3. Promises
2 Likes

What is the difference between synchronous and asynchronous functions?
- Synchronous functions happen one at a time, where asynchronous functions may use an additional thread to manage the event loop of other functions in the background.

Additional Note: A callback is the function we give to an event.

What is callback hell?
- Callback hell is the confusion and complexity in code that quickly escalates when using asynchronous callback functions.

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.”

2 Likes

1- Synchronous functions finish their execution one by one, that is to say, the second function call will wait the first function call to finish. Asynchronous functions could be executing parallel while other functions are executing in the main thread
2- Callback hell is when you call a function which receive a function, which receive a function, which receive a function … and so on … Usually this chunk of code looks like a rotated pyramid
3- We can avoid callback hell in many ways like: promises, async / await, futures

1 Like

1. JavaScript is single-threaded which means only one section of code can be run at one time. Functions that block any further code from beeing executed are called synchronous. Functions that can be initiated and put aside are called asynchronous. Those are pretty useful for something like API calls where the browser might have to wait quite some time for a response.

2. A callback hell is caused when people try to write JavaScript in a way where execution happens visually from top to bottom while using a lot of asynchronous functions (callbacks). The code will become really messy and hard to maintain depending on how many nested functions are used.

3. Promises can be used to write asynchronous code that still appears as though it is executing in a top-down way.

2 Likes
  1. Synchronous functions operate one at a time and stop all other executions until they are done. Asynchronous functions executes in concurrence with other functions and dont need to wait for other functions to finish execution before they can go on ahead with what they’re doing.
  2. Callback hell is when many asynchronous functions are held up by waiting for other nested functions to finish execution, essentially holding up the whole process.
  3. With Promises and allowing our code to wait for others to finish executing so they have the appropriate resources to continue.
1 Like

1-

In a single-threaded environment, only one section of code can be running at any one time.
Tasks like these that occupy Javes’ full attention are called blocking or synchronous.

An asynchronous task can be initiated and then put aside until a later date while another task has begun.

2-

Callback hell is a situation where several functions are being performed in nested form.

3-

Promise is used to solve the call back hell situation. jQuery, AngularJS come with promise library. It also handles errors

1 Like
  1. Synchronous functions has code which is executed seqentially so second statement wait for the first to finish execution. This call result in long waits and non-responsive of your website when it is executing certain code which takes long time to finish. Asynchronous functions helps in these situations as these can execute idependently of the main branch of the code.

  2. Callback is used to notify the main branch or handler of the completion of the inner handler and arrival of the result.

  3. jQuery provides Promises and Meteor does it via Fibers package.

1 Like

1. What is the difference between synchronous and asynchronous functions? Synchronous functions are executed in sequence, where each task begins once the previous one has finished. On the other hand asynchronous functions can be initiated and then put aside until a result is available to be operated on, this means that other tasks can continue whilst we wait for the result.

2. What is callback hell? Callback hell occurs when you have an excessive number of callbacks nested within one another, making the code overly complex to manage.

3. Which technique can help us solve callback hell? Promises allows us to chain callbacks and deal with errors, which helps make the code easier to read and manage.

1 Like

What is the difference between synchronous and asynchronous functions? You have to wait for it to finish before moving on to another task. you can excecute on to another task before it finishes
What is callback hell?Many programmers get stuck in the callback hell because of bad programming practices, they do not really plan the structure of their code and they do not realize how badly it is structured until it’s too late
Which technique can help us solve callback hell? The best Practices like: planning the code, code in order, and name the part of the program in the most intuitive way possible

1 Like

What is the difference between synchronous and asynchronous functions?

The difference is the way which are executed, synchronous functions are executed sequentially and asynchronous are executed when an event occurs

What is callback hell?

When you have a lot of nested callbacks

Which technique can help us solve callback hell?

Using promises or async await syntax

2 Likes
  1. What is the difference between synchronous and asynchronous functions?
  2. Synchronous functions follow a single threading environment which can execute a single selection of code at any one time. Asynchronous functions, on the other hand, are initiated and set aside to execute the callback at a later time. The Javascript engine's background threat that manages the event loop, JavaScript's to do list.

  3. What is callback hell?
  4. In JavaScript callback is just a name convention of using JavaScript functions. There isn't a special thing called a 'call back'. Callback hell is a problem when executing many nested functions and it is the issue with tracking the number of indentions an "})" signs needed, and thus understanding the order that things execute as a program runs.

  5. Which technique can help us solve callback hell?
  6. By giving function names and declaring them at the top level, taking them out nested function, simplifies the reading of code. By making code modular, it allows code to be reused. These two simple ways of coding will make it so you never run into callback hell. Finally handle every error. In Node.js the first argument to the callback is always reserved for an error. It’s a convention that encourages to handle your errors.

2 Likes

1- Synchronous functions are executed sequentially from top to bottom and javascript waits to finish one before executing another one. An asynchronous function can be initiated and then put aside until a later date while javascript gets started on the next task on its to-do list which is called the event loop.

2- complex operations tend to produce more levels and sub-levels, which is what is poetically known as callback hell.

3- 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.
But in Node.js, we can use a different approach. By extending the runtime, we can abstract away the asynchronicity and write code that looks sychronous.

  1. Synchronous functions happen one at a time, where asynchronous functions may use an additional thread to manage the event loop of other functions in the background.

  2. Callback hell is the confusion and complexity in code that quickly escalates when using asynchronous callback functions.

  3. 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. But in Node.js, we can use a different approach. By extending the runtime, we can abstract away the asynchronicity and write code that looks sychronous.

  1. Whereas a synchronous task will occupy Javes continuously until its completion, an asynchronous task can be initiated and then put aside until a later date while our valet gets started on the next task on his to-do list.
    2.Callback hell is an undesirable situation whereby several nested callback functions are needed in order to perform relatively simple tasks. This makes our code harder to write, debug and maintain.
    3,By extending the runtime, we can abstract away the asynchronicity and write code that looks sychronous , PROMISES